Page 1 of 1

Shell get yesterdays date

Posted: Mon May 27, 2013 5:49 pm
by mister_v
He

I trying to get yesterdays date using the command date.

I have the following command:

Code: Select all

date +"%A, %B %-d, %Y"
But that is for today's date.

Re: Shell get yesterdays date

Posted: Mon May 27, 2013 6:49 pm
by chris
You can do this by adding --date="-1 day"

Code: Select all

date +"%A, %B %-d, %Y" --date="-1 day"
or even shorter

Code: Select all

date +"%A, %B %-d, %Y" -d yesterday
You can also get the day for tomorrows or work with months or week.

Code: Select all

date +"%A, %B %-d, %Y" -d tomorrow
date +"%A, %B %-d, %Y" 
date +"%A, %B %-d, %Y" -d "-1 month"
date +"%A, %B %-d, %Y" -d '3 weeks ago'