Re: How to manipulate date inside a shell script (580 Views)
Reply
Frequent Advisor
Posts: 86
Registered: ‎03-03-2002
Message 1 of 8 (580 Views)
Accepted Solution

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
Acclaimed Contributor
Posts: 17,825
Registered: ‎07-16-1998
Message 2 of 8 (580 Views)

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.
Frequent Advisor
Posts: 86
Registered: ‎03-03-2002
Message 3 of 8 (580 Views)

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
Acclaimed Contributor
Posts: 17,825
Registered: ‎07-16-1998
Message 4 of 8 (580 Views)

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.
Frequent Advisor
Posts: 86
Registered: ‎03-03-2002
Message 5 of 8 (580 Views)

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
Frequent Advisor
Posts: 86
Registered: ‎03-03-2002
Message 6 of 8 (580 Views)

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
Acclaimed Contributor
Posts: 17,825
Registered: ‎07-16-1998
Message 7 of 8 (580 Views)

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
Frequent Advisor
Posts: 86
Registered: ‎03-03-2002
Message 8 of 8 (580 Views)

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
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.