Operating System - HP-UX
1834500 Members
2936 Online
110068 Solutions
New Discussion

date calculation within Unix

 
SOLVED
Go to solution
Jim Tropiano_1
Frequent Advisor

date calculation within Unix

Need to know if there is a way to calculate a date
for example
calculating the date 5 days ago or 18 months ago.
5 REPLIES 5
Pete Randall
Outstanding Contributor
Solution

Re: date calculation within Unix

Clay Stephenson's caljd.sh script (attached) will handle this. Invoke as "caljd.sh -u" for usage details.


Pete

Pete
James R. Ferguson
Acclaimed Contributor

Re: date calculation within Unix

Hi Jim:

You can also use perl to do things like this:

For instance, suppose you want the date 3-days ago:

perl -le '$now=(time)-3*86400;print scalar localtime($now)'

Regards!

...JRF...
Robert-Jan Goossens_1
Honored Contributor

Re: date calculation within Unix

Jim,

Add on to Pete's answer,

create a small script to for show for example the date 360 days ago.

#!/usr/bin/ksh
CALJD=/usr/local/bin/caljd.sh
# set date 3 days back
RMDATE=$($CALJD -Y -s $($CALJD -p +360))
echo $RMDATE

Best regards,
Robert-Jan
Jim Tropiano_1
Frequent Advisor

Re: date calculation within Unix

Thanks as always
Jim Tropiano_1
Frequent Advisor

Re: date calculation within Unix

thanks