I am running SunOS.
bash-3.00$ uname -a
SunOS lvsaishdc3in0001 5.10 Generic_142901-02 i86pc i386 i86pc
I need to find Yesterday's date in linux
with the proper formatting passed from command prompt. When I tried like this on my shell prompt-
bash-3.00$ date --date='yesterday' '+%Y%m%d'
date: illegal option -- date=yesterday
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
I always get date illegal option
, why is it so?
Is there anything wrong I am doing?
Update:-
bash-3.00$ date --version
date: illegal option -- version
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
A pure bash solution
As larsks suggested, you can use perl:
Slightly modified from
http://blog.rootshell.be/2006/05/04/solaris-yesterday-date/
To get YYYYMMDD format use this
This link explains how to format date and time with strftime
http://perltraining.com.au/tips/2009-02-26.html
TZ=$TZ+24 date +'%Y/%m/%d'
in SunOS.Try this below thing. It should work
Try this one out:
where GMT is the time zone and you might need to alter the 24 according to the hours difference you have from GMT. Either that or you can change GMT to a time zone more comfortable to you e.g. CST
Playing on Solaris10 with non-GMT environment, I'm getting this:
As You colud see, I have and I want to get CEST , but TZ=CEST+24 giving me wrong CEST data; GMT+24 giving me correct data, but unusable.
To get the proper result, I has to use GMT+22 (wrong command, correct result) or CEST+22 (wrong value, but finnaly correct result for correct TZ)