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

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


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


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

date -j -v-1dWed 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