Re: How to manipulate date inside a shell script (178 Views)
Reply
Frequent Advisor
Augusto Vinhaes
Posts: 86
Registered: ‎03-03-2002
Message 1 of 8 (178 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
Please use plain text.
Acclaimed Contributor
A. Clay Stephenson
Posts: 17,825
Registered: ‎07-16-1998
Message 2 of 8 (178 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.
Please use plain text.
Frequent Advisor
Augusto Vinhaes
Posts: 86
Registered: ‎03-03-2002
Message 3 of 8 (178 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
Please use plain text.
Acclaimed Contributor
A. Clay Stephenson
Posts: 17,825
Registered: ‎07-16-1998
Message 4 of 8 (178 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.
Please use plain text.
Frequent Advisor
Augusto Vinhaes
Posts: 86
Registered: ‎03-03-2002
Message 5 of 8 (178 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
Please use plain text.
Frequent Advisor
Augusto Vinhaes
Posts: 86
Registered: ‎03-03-2002
Message 6 of 8 (178 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
Please use plain text.
Acclaimed Contributor
A. Clay Stephenson
Posts: 17,825
Registered: ‎07-16-1998
Message 7 of 8 (178 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.
Please use plain text.
Frequent Advisor
Augusto Vinhaes
Posts: 86
Registered: ‎03-03-2002
Message 8 of 8 (178 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
Please use plain text.
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