How to gwt 60 days old date in ksh

January 25, 2011 at 04:59:08
Specs: Windows XP
I need a 60 days old date from current date,will be store in veriable.

supoose current date is 25 jan 2011 so date 60 days before is 27 Nov

will be store in variable "Nov 27" Formet.

thanx in advance

See More: How to gwt 60 days old date in ksh

Report •

January 25, 2011 at 09:37:34
Date arithmetic has been discussed a lot in this forum. Check out this link:

Within this link, William Robert's shift_date script is discussed. Here is a link to the script:


Report •

January 26, 2011 at 22:44:28
Hi nails

thanx for your help

But all the script is too long

is there any short script for that to get 60 days old date?

Report •

January 27, 2011 at 10:06:27
I have been chastised before for providing a wrong solution, but never one that is too long.

Date arithmetic in the unix shell is NOT an easy topic:

Report •

Related Solutions

March 4, 2011 at 02:42:15
This is easy if your date command in UNIX supports the -D flag:
First get seconds since 1970:
# today=`date +%s`
If you ran this at 10:00 on 25 jan 2011, this would give 1295949600 (I used 'date -d "2011-01-25 10:00" +%s' to give me this as today is not in Jan ! )
Then subtract 60 days in seconds (60*60*24*60=5184000):
# let date60=today-5184000
This gives 1290765600 and you then need -D flag to show your date:
# date -D %s -d $date60
Fri Nov 26 10:00:00 UTC 2010

Note this gives the correct calc of 26th Nov (you had 27th in your example)


Report •

March 4, 2011 at 12:08:09

The date command extensions you are using are GNU extentions so you probably should mention that it's easy if you are running Linux. Unfortunately, GNU is not Unix :). This date issue was mentioned in this thread:

Report •

Ask Question