I want to get yesterday date in YYYY-MM-DD format.
In bash, I can get it by using date '+%F' -d "1 day ago". It gives the output as 2015-09-02.
How can I get the same result in ksh?
Ksh's printf supports datetime manipulation:
# echo ${.sh.version} Version AJM 93u+ 2012-08-01 # printf '%(%Y-%m-%d)T\n' today 2015-09-03 # printf '%(%Y-%m-%d)T\n' yesterday 2015-09-02 # printf '%(%Y-%m-%d)T\n' '5 days ago' 2015-08-29 # day before yesterday isn't recognized. You have to say that differently in GNU date, too, but … still, interesting.
2015-09-02inkshas well.date '+%F' -d "yesterday"uname -a.datecomes from that. If you're on a different platform, such as Solaris or perhaps Mac OS X, then you get a differentdateprogram. Your issue is then "how can I make a non-GNUdateproduce the same answer as GNUdate?" The simplest answer is probably "Install GNU CoreUtils on this other machine". If you're on the same machine, you'll be using the samedateprogram and should not run into this problem at all.datecommand are independent of which shell you are using.