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


Question

How can I print the date which is a day before current time in Bash?

1
156
11/10/2009 9:36:28 PM

Accepted Answer

Sorry not mentioning I on Solaris system. As such, the -date switch is not available on Solaris bash.

I find out I can get the previous date with little trick on timezone.

DATE=`TZ=MYT+16 date +%Y-%m-%d_%r`
echo $DATE
4
11/11/2009 2:16:44 AM

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

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon