Operating System - HP-UX
1748222 Members
4445 Online
108759 Solutions
New Discussion юеВ

Re: DATE 'n' Days Ago or After from Current Date

 
SOLVED
Go to solution
Neoma
Frequent Advisor

DATE 'n' Days Ago or After from Current Date

Hi All,
I want to write a script to get a date 3 days (calender days) ago from current date or after from current date.

The easiest method could be to use %j in date cmd and get the day of the year (current year) in decimal format and minus (or add ) number of days "n" for which you want the date.
Now after getting this number how to get the date of thay day of the year is my problem?
I would really appreciate if someonoe can suggest other way of getting the end result?
3 REPLIES 3
James R. Ferguson
Acclaimed Contributor
Solution

Re: DATE 'n' Days Ago or After from Current Date

Hi:

Use Perl;

# perl -MPOSIX -le 'print strftime "%Y-%m-%d",localtime(time-(3*60*60*24))'
2008-09-11

perl -MPOSIX -le 'print strftime "%Y-%m-%d",localtime(time+(3*60*60*24))'
2008-09-17

You can use the same formatting directives you use with the Unix 'date' command by using 'strftime':

# perl -MPOSIX -le 'print strftime "%b %d",localtime(time-(3*60*60*24))'
Sep 11

Regards!

...JRF...
Neoma
Frequent Advisor

Re: DATE 'n' Days Ago or After from Current Date

Thanx you Very much.

Great..
Neoma
Frequent Advisor

Re: DATE 'n' Days Ago or After from Current Date

.