linux date command

Posted by david marsh on Thu 15 March 2012

this is cool, i used to do all sorts of hacks to do this at one time:

davidmarsh@server:~$ date +%A --date today-1days
Wednesday

davidmarsh@server:~$ date +%A --date today+1days
Friday

davidmarsh@server:~$ date +%A --date yesterday
Wednesday

davidmarsh@server:~$ date +%A --date "2 days ago"
Tuesday

works as expected for other variables

davidmarsh@server:~$ date +%Y --date "last year"
2011

davidmarsh@server:~$ date --date "next monday"
Mon Mar 19 00:00:00 EST 2012

DATE STRING

The --date=STRING is a mostly free format human readable date string such as "Sun, 29 Feb 2004 16:21:42 -0800" or "2004-02-29 16:21:42" or even "next Thursday". A date string may contain items indicating calendar date, time of day, time zone, day of week, relative time, relative date, and numbers. An empty string indicates the beginning of the day. The date string format is more complex than is easily documented here but is fully described in the info documentation.

damn you info docs!

tags: linux, unix, it