unix - Get the date (a day before current time) in Bash

ID : 20092

viewed : 18

Tags : bashunixdatesolarisbash

Top 5 Answer for unix - Get the date (a day before current time) in Bash

vote vote

97

if you have GNU date and i understood you correctly

$ date +%Y:%m:%d -d "yesterday" 2009:11:09 

or

$ date +%Y:%m:%d -d "1 day ago" 2009:11:09 
vote vote

87

If you have BSD (OSX) date you can do it like this:

date -j -v-1d Wed Dec 14 15:34:14 CET 2011 

Or if you want to do date calculations on an arbitrary date:

date -j -v-1d -f "%Y-%m-%d" "2011-09-01" "+%Y-%m-%d" 2011-08-31 
vote vote

72

date --date='-1 day' 
vote vote

64

MAC OSX

For yesterday's date:

date -v-1d +%F 

where 1d defines current day minus 1 day. Similarly,

date -v-1w +%F - for previous week date

date -v-1m +%F - for previous month date

IF YOU HAVE GNU DATE,

date --date="1 day ago" 

More info: https://www.cyberciti.biz/tips/linux-unix-get-yesterdays-tomorrows-date.html

vote vote

54

Well this is a late answer,but this seems to work!!

     YESTERDAY=`TZ=GMT+24 date +%d-%m-%Y`;      echo $YESTERDAY; 

Top 3 video Explaining unix - Get the date (a day before current time) in Bash

Related QUESTION?