Operating System - HP-UX
1753333 Members
5289 Online
108792 Solutions
New Discussion юеВ

finding a date value of 15 days before

 
sekar sundaram
Honored Contributor

finding a date value of 15 days before

Hi,

Lets say a date - May 05, i would like to find out the date of 15 days before this date.

Please suggest....thanks...
7 REPLIES 7
Matti_Kurkela
Honored Contributor

Re: finding a date value of 15 days before

Which programming/scripting language you're using?

Generally, the algorithm would be: convert the date to a Unix timestamp, subtract 15 days (15 * 24 * 60 * 60 seconds) from the timestamp value, then convert the timestamp back to a human-readable date.

If you're using some scripting/programming language (Java, C, Perl, etc.) that can use the standard POSIX ctime(3) and mktime(3) functions, or has other similar functions as standard, this would be easy to implement; with HP-UX standard POSIX shell scripting, not so easy.

Attached is the caljd.sh script by ITRC forums veteran A. Clay Stephenson; use "chmod a+rx caljd.sh" to make it executable, then run "./caljd.sh --help" to get complete instructions for its use.

Example: (the date of 2011-05-05 minus 15 days)

./caljd.sh -y $(./caljd.sh -p 15 -y 2011 05 05)
2011 04 20

MK
MK

Re: finding a date value of 15 days before

sekar sundaram
Honored Contributor

Re: finding a date value of 15 days before

Great, thanks ...
i have searched actually,..i remember a post(how to get yesterday's date thru scripting), i searched, but no luck, so i created this post...ok, i will check both....thanks again...
Dennis Handly
Acclaimed Contributor

Re: finding a date value of 15 days before

Do you need to worry about a time 15 days before a date? That may have a DST transition where it may go back an extra day because of a loss of an hour.
ctime(3) would have that issue, unless you picked a time like 1200.
sekar sundaram
Honored Contributor

Re: finding a date value of 15 days before

sundar@sunrise> perl -MPOSIX -le 'print strftime "%b %d",localtime(time-(60*60*24*25))'
May 01

got it...thanks GURU's...
James R. Ferguson
Acclaimed Contributor

Re: finding a date value of 15 days before

Hi Sekar:

Your original query suggests that you want to find the date that was 15-days before some arbitrary date; not necessarily 15-days before today.

For that, see my offering in the link Duncan cited.

Regards!

...JRF...
Wilfred Chau_1
Respected Contributor

Re: finding a date value of 15 days before

check out the Date::Manip module, look at the syntax.

perl -MDate::Manip -e 'print DateCalc("today", "+ 4 days"). "\n"'