https://wiki.hackspherelabs.com/index.php?title=Date&feed=atom&action=historyDate - Revision history2024-03-29T11:23:39ZRevision history for this page on the wikiMediaWiki 1.27.1https://wiki.hackspherelabs.com/index.php?title=Date&diff=1574&oldid=prevWebdawg: Created page with "*http://blog.sleeplessbeastie.eu/2011/12/15/how-to-find-yesterdays-or-tomorrows-date-using-shell/ How to find yesterday's or tomorrow's date using shell? Posted on December,..."2013-11-02T01:07:14Z<p>Created page with "*http://blog.sleeplessbeastie.eu/2011/12/15/how-to-find-yesterdays-or-tomorrows-date-using-shell/ How to find yesterday's or tomorrow's date using shell? Posted on December,..."</p>
<p><b>New page</b></p><div>*http://blog.sleeplessbeastie.eu/2011/12/15/how-to-find-yesterdays-or-tomorrows-date-using-shell/<br />
<br />
<br />
How to find yesterday's or tomorrow's date using shell?<br />
Posted on December, 15 2011 by milosz<br />
<br />
There are couple of different ways to perform this task using shell date command depending on used OS. I will concentrate on Ubuntu Linux, OpenBSD and FreeBSD.<br />
Ubuntu Linux<br />
<br />
Ubuntu Linux offers -d switch to find the answer.<br />
<br />
$ date --version<br />
date (GNU coreutils) 8.5<br />
...<br />
<br />
Current date:<br />
<br />
$ date<br />
Thu Dec 15 21:37:53 CET 2011<br />
<br />
Calculate yesterday's date:<br />
<br />
$ date -d "yesterday"<br />
Wed Dec 14 21:38:02 CET 2011<br />
$ date -d "last day"<br />
Wed Dec 14 21:38:03 CET 2011<br />
$ date -d "-1 day"<br />
Wed Dec 14 21:38:05 CET 2011<br />
<br />
Calculate tomorrow's date:<br />
<br />
$ date -d "tomorrow"<br />
Fri Dec 16 21:39:20 CET 2011<br />
$ date -d "next day"<br />
Fri Dec 16 21:39:22 CET 2011<br />
$ date -d "+1 day"<br />
Fri Dec 16 21:39:25 CET 2011<br />
<br />
OpenBSD<br />
<br />
Using OpenBSD this task needs to be performed in different way as there is no equivalent switch.<br />
<br />
Current date:<br />
<br />
$ date<br />
Thu Dec 15 22:15:07 CET 2011<br />
<br />
Calculate yesterday's date:<br />
<br />
$ date -r `expr $(date +%s) - 86400` <br />
Wed Dec 14 22:15:09 CET 2011<br />
<br />
Calculate tomorrow's date:<br />
<br />
$ date -r `expr $(date +%s) + 86400` <br />
Fri Dec 16 22:15:11 CET 2011<br />
<br />
FreeBSD<br />
<br />
FreeBSD offers handy -v switch to perform this task.<br />
<br />
Current date:<br />
<br />
$ date<br />
Thu Dec 15 22:18:14 CET 2011<br />
<br />
Calculate yesterday's date:<br />
<br />
$ date -v-1d<br />
Wed Dec 14 22:18:18 CET 2011<br />
<br />
Calculate tomorrow's date:<br />
<br />
$ date -v+1d<br />
Fri Dec 16 22:18:22 CET 2011</div>Webdawg