DATE 'n' Days Ago or After from Current Date (70 Views)
Reply
Frequent Advisor
Neoma
Posts: 78
Registered: ‎11-06-2007
Message 1 of 4 (70 Views)
Accepted Solution

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?
Please use plain text.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 2 of 4 (70 Views)

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...
Please use plain text.
Frequent Advisor
Neoma
Posts: 78
Registered: ‎11-06-2007
Message 3 of 4 (70 Views)

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

Thanx you Very much.

Great..
Please use plain text.
Frequent Advisor
Neoma
Posts: 78
Registered: ‎11-06-2007
Message 4 of 4 (70 Views)

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

.
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