Shell get yesterdays date

Bash shell is the common linux command language.
Post Reply
mister_v
Posts: 177
Joined: Thu Mar 04, 2010 9:19 pm

Shell get yesterdays date

Post 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.
chris
Site Admin
Posts: 180
Joined: Mon Jul 21, 2008 9:52 am

Re: Shell get yesterdays date

Post 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'
Post Reply