1833744 Members
2643 Online
110063 Solutions
New Discussion

date command problem

 
SOLVED
Go to solution
xumingyong
Occasional Contributor

date command problem

How to get the date of yesterday under date command?

I checked the manual, it seems not possible.

could someone provide the shell code for me to solve this question?

Best
3 REPLIES 3
Johnson Punniyalingam
Honored Contributor
Solution

Re: date command problem

Try the following command at your unix prompt:

perl -e 'print localtime(time() - 86400) . "\n" '

If your unix machine has Perl installed, then it will work.

Check below link Use the date_calc script to calculate the date you need then pass it as a parameter to your script

http://www.unix.com/unix-dummies-questions-answers/4870-days-elapsed-between-2-dates.html#post16559

Thx,
Johnson
Problems are common to all, but attitude makes the difference
Heironimus
Honored Contributor

Re: date command problem

Depending on your environment and your needs it might be easier to grab GNU date (part of coreutils), which lets you do nifty things like "date -d yesterday". Just make sure GNU date isn't in your system-wide PATH or give it a different name so that you don't have any problems with tools that expect HP's date.