Results 1 to 7 of 7
Greetings,
I'm new to Linux and I'm trying to detemine how to get the date that was 2 days ago. My experience is primarily with HP Tru64 UNIX and on ...
- 06-05-2007 #1Linux User
- Join Date
- Jun 2007
- Posts
- 318
How to determine date 2 days ago
Greetings,
I'm new to Linux and I'm trying to detemine how to get the date that was 2 days ago. My experience is primarily with HP Tru64 UNIX and on it this command works (The date being 20070605):
# (export TZ; TZ=UTC+48; date '+%Y%m%d')
20070603
On RedHat Linux I get yesterday's date:
# (export TZ; TZ=UTC+48; date '+%Y%m%d')
20070604
So, what's the proper way to do this on Linux.
Thanks,
Vic
- 06-05-2007 #2
You could do something like this:
shell> expr $(date '+%Y%m%d') - 2
- 06-05-2007 #3Linux User
- Join Date
- Jun 2007
- Posts
- 318
- 06-05-2007 #4
Hmmm...I overlooked that.
Maybe perl could lend its assistance:
The 2 on the end could be replaced with any number. That is the number of days to subtract from the current day.Code:perl -le 'printf("%04d%02d%02d\n",(localtime(time-(86400*$ARGV[0])))[5] + 1900,(localtime(time-(86400*$ARGV[0])))[4],(localtime(time-(86400*$ARGV[0])))[3])' 2
- 06-05-2007 #5Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Try this:
RegardsCode:date --date='2 days ago'
- 06-05-2007 #6Linux User
- Join Date
- Aug 2006
- Posts
- 458
you can type 'info date" and see some examples of how to use the GNU date "2 days ago" example.. (assuming you have info and GNU date of course)
- 06-05-2007 #7Linux User
- Join Date
- Jun 2007
- Posts
- 318


Reply With Quote
