Script to get previous date for the given input date..

hi all,
need a script or command to get the previous date for the given input date...

like in my script i will pass date as input parameter like 2014-12-01 and i want the output as previous date.. ie.. 2014-11-30

Hello hemant,

Following may help you in same.

Here is the script.

cat days_ago.ksh
date -d"$1 days ago"

Run the script as follows.

./days_ago.ksh 20 ##### By giving number of days ago you need as arguments

Output will be as follows.

Tue Nov 11 07:48:52 EST 2014
 

Where current date is 1st Dec 2014

EDIT: To get exactly in YYYY-MM-DD format as follows code may help.

cat days_ago.ksh
date -d"$1 days ago" +%Y-%m-%d

Output will be as follows.

./days_ago.ksh 20
2014-11-11

Thanks,
R. Singh

I think the OP doesn't want "minus N days from the current date"...
---
If you have GNU date , try this

$ date -d "2014-12-01 -1 day" +%Y-%m-%d
2014-11-30
$