Get yesterday’s date into a variable on AIX

As many of you know default date command on AIX doesn’t support “–date” parameter as Linux systems do. So, what can you do if you want to display another date in your shell script? There are some scripts roaming around the web, but the simplest thing i found is this. Get your time zone (let’s say +1) and substract 24 hours from it (we get 23). Then we change our timezone by setting TZ environment variable to new one and execute date command like this:

# YESTERDAY=$(TZ=EST23EDT date)
# echo $YESTERDAY
Mon 1 Mar 2010 12:06:33
# date
Tue 2 Mar 2010 12:06:39

You can insert any number instead of number “23” used in this script (EST<any integer number>EDT). This allows you to add or subtract as many hours as you want.

Share the joy

5 thoughts on “Get yesterday’s date into a variable on AIX”

  1. This is exactly what I need. I did create a script on Linux and now wanted to run this on AIX and HP. Thank you!

  2. I copied your script and it looks not right???

    Tue May 22 17:11:41 EDT 2012
    Wed May 23 11:11:41 EDT 2012

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.