Get Yesterday's date in solaris

2019-02-17 07:29发布

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]

7条回答
一纸荒年 Trace。
2楼-- · 2019-02-17 08:31

A pure bash solution given by @olivecoder is very reliable compared to any other solution but there is a mistake to be corrected. when the day fall on 1st of the month the script is failing with date saying "last_day_of_month" in day value. @olivecoder has missed $ in day=last_day_of_month, that it should be

day=$last_day_of_month;

After this correction it works very good.

Using Timezone -24 is having some issue based on time when use it. in some cases it goes to day before yesterday. So I think its not reliable.

查看更多
登录 后发表回答