How to get previous day from UNIX AIX?

Does anybody know how to get previous day on UNIX AIX?

I tried

TZ=XYZ+24 date '+%y%m%d' 

But it doesn't understand

Thanks for contribution

Hello digioleg54,

If you have GNU date in your system then following may help you in same.

 date -d"1 day ago"
 

Thanks,
R. Singh

No, our system is very old. we don't have GNU

Just in case you missed it: we a have a special AIX-forum dedicated to the best UNIX-OS of them all. ;-))

In fact your system is not necessarily old but simply POSIX - AIx uses POSIX-compliant utilities and the POSIX- date doesn't have the -d flag.

You can do the following: (every) UNIX, including AIX, maintains the time as a (permanently updated) 32-bit (64-bit?) integer, which is counting the seconds since 0:00 Jan 1st 1970. "Time" is generally maintained in CUT (coordinated universal time, basically GMT) systemwide, from this the "TZ"-string is "added". You can modify the TS-string which contains an offset to the system time, for a single command like this:

# echo $TZ
GMT-1
# date ; TZ=GMT+23 date
Tue Mar 21 14:35:15 CET 2017
Mon Mar 20 14:35:15 GMT 2017

You can, the same way, subtract or add arbitrary values by adding/subtracting multiples of 24 from/to the TZ-offset:

# date ; TZ=GMT+23 date ; TZ=GMT+47 date
Tue Mar 21 14:37:39 CET 2017
Mon Mar 20 14:37:39 GMT 2017
Sun Mar 19 14:37:39  2017
# date ; TZ=GMT-25 date ; TZ=GMT-49 date
Tue Mar 21 14:38:57 CET 2017
Wed Mar 22 14:38:57 GMT 2017
Thu Mar 23 14:38:57 GMT 2017

Apply necessary format codes normally to the date -command.

I hope this helps.

bakunin

1 Like
# usage then.pl 7 for date seven days ago
ago()
{
   perl -e ' my $delta = $ARGV[0];
             $delta*=86400;
             $delta=time - $delta;
             @t=localtime( $delta );
             printf("%02d-%02d-%d", $t[4]+1, $t[3], $t[5]+1900); ' $1
}

echo $(ago $1)

For yesterday:

 ./then.pl 1

to change the date format rearrange the printf statement. t is an array see examples here:

localtime - perldoc.perl.org

perl -e 'printf "%s\n",scalar localtime(time-86400)'
perl -MPOSIX -e 'print POSIX::strftime("%Y%m%d%H%M\n", localtime(time-86400));'

I believe you can also do this on AIX - don't have AIX to validate:

echo $(echo '*time-0t86400=Y' | /usr/bin/adb -k | tail -2)

I'm not sure you need the + on your original command. I wrote a whole pile of things to exploit the fact that AIX recognises huge TZ offsets to work out what days we had to reports against and what days we had to write projections for (i.e. direct-debit due dates etc.)

I think it is just:-

# Save current TZ first
orig_TZ=$TZ

TZ=GMT24BST         # as appropriate
date '+%Y %m %d'    # grab this somehow

TZ=GMT72BST         # 3 days ago
date '+%Y %m %d'    # grab this somehow

TZ=GMT-48BST        # 2 days future
date '+%Y %m %d'    # grab this somehow

# Reset to original TZ
TZ=orig_TZ