Simpler Navigation coming for Servers and Operating Systems
Coming soon: a much simpler Servers and Operating Systems section of the Community. We will combine many of the older boards, and you won't have to click through so many levels to get at the information you need. If you are looking for an older board and do not find it, check the consolidated boards, as the posts are still there.
General
cancel
Showing results for 
Search instead for 
Did you mean: 

How to manipulate date inside a shell script

SOLVED
Go to solution
Augusto Vinhaes
Frequent Advisor

How to manipulate date inside a shell script

I'm writing a shell script and I need to deduct date (manipulate date). Any idea will be appreaciated.

Regards,
Augusto
Augusto
7 REPLIES
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: How to manipulate date inside a shell script

My "one size fits all" for date problems is caljd.sh. Invoke as caljd.sh -u for full usage and examples or if you will give me an idea of what you arte trying to do, I can probably provide the syntax.

If it ain't broke, I can fix that.
Augusto Vinhaes
Frequent Advisor

Re: How to manipulate date inside a shell script

Hi Clay!

Thank you for the help. The script you sent me is very powerfull. I've got one more question: Is the script able to treat bi-sixth years ?

Regards,
Augusto
Augusto
A. Clay Stephenson
Acclaimed Contributor

Re: How to manipulate date inside a shell script

I have no idea what a "bi-sixth" year is. I felt bad until I found that Google didn't know either. Can you explain a bit?
If it ain't broke, I can fix that.
Augusto Vinhaes
Frequent Advisor

Re: How to manipulate date inside a shell script

I will try... in a bi-sixth year such as 2000 the February month has 29 days (instead of 28 days).

Regards,
Augusto
Augusto
Augusto Vinhaes
Frequent Advisor

Re: How to manipulate date inside a shell script

Hi Clay !

I've tested your script and it works for bi-sixth years:

$ ./24089.sh -e 01 03 2000
2451605
$ ./24089.sh -e -p 1 2451605
29 02 2000

Thanks
Augusto
A. Clay Stephenson
Acclaimed Contributor

Re: How to manipulate date inside a shell script

We would call that century years (which are normally not leap years) divisible by 400 -- which are leap years --- and, yes, caljd.sh handles that.

Try this:
caljd.sh 2 28 2000
2451603
Now let's send in the next Julian day and see what the Gregorian Date is.
caljd.sh 2451604
02 29 2000
Now let's send in two days later:
caljd.sh 2451605
03 01 2000

Now for a quick method to determine the day after 2 28 2000.
DT=$(caljd.sh $(caljd.sh -n 1 2 28 2000))
echo "${DT}"
2 29 2000
If it ain't broke, I can fix that.
Highlighted
Augusto Vinhaes
Frequent Advisor

Re: How to manipulate date inside a shell script

Sorry, we call bi-sixth years here in Brazil. It's a very good script to manipulate date.

Thanks a lot,
Augusto
Augusto