Changing Date Format

How can i make the date command output yesterday's date, current date and the date 4 days ago, in the following format:

2012-10-03

code:

date +%  ????

Try like..

date -d yesterday +%Y%m%d 
1 Like

Try searching

http://www.unix.com/answers-frequently-asked-questions/13785-yesterdays-date-date-arithmetic.html

1 Like

With GNU date:

Current date: date +%Y-%m-%d

Yesterday's date: date -d "-1 day" +%Y-%m-%d

4 days ago: date -d "-4 days" +%Y-%m-%d

You can start by reading man date

1 Like