How to display yesterday Date in AIX

Hi,

I need help to display the yesterday date in format mentioned below:

2012-06-26-PM

I tried this but it displays current date:

`date +%Y-%m-%d-%p`

explore http://www.unix.com/answers-frequently-asked-questions/13785-yesterdays-date-date-arithmetic.html

For linux (GNU date) Try.

date --date '1 day ago' +%Y-%m-%d-%p

Try this:

date +%Y-%m-%d-%p -d yesterday

I tried both but it gives me error:

date +%Y-%m-%d-%p -d yesterday
Error:date: 0551-402 Invalid character in date/time specification.
Usage: date [-u] [+"Field Descriptors"]
date --date '1 day ago' +%Y-%m-%d-%p
Error :date: Not a recognized flag: -
Usage: date [-u] [+"Field Descriptors"]

What OS version are you on since the Linux date utility is very powerful and can display dates in many formats depending on the supplied options...

AIX saturn 3 5 00044BB7D600

Ah, you mentioned "Linux" in the title. That took me in the wrong direction.

Try:

perl -le'print scalar localtime time - 86400 * shift' 1

Use 2 ... n to get n days ago:

% perl -le'print scalar localtime time - 86400 * shift' 1  
Mon Jun 25 21:11:53 2012
% perl -le'print scalar localtime time - 86400 * shift' 366
Sun Jun 26 21:11:55 2011
1 Like

Yes,
I've fixed the title ...

1 Like