I am posting this in both the General UNIX forum and the UNIX scripting forum since I have seen so many people suggest using the TZ trick described in [faq80-953] to find yesterday's date. Unfortunately the trick is flawed, unless you are using Greenwich Mean Time. To see the problem, try this using ksh or a similarly capable shell (that's a capable shell, not csh!)
$ date
Thu Oct 3 19:30:00 CDT 2002
$ TZ="$TZ+24" date
Thu Oct 3 00:30:17 CDT 2002
As you can see, appending "+24" to TZ did not yield yesterday's date. Why? because of where I am: the USA Central Timezone (in daylight savings time), as is indicated by the "CDT". Between May and October we are 5 hours behind CUT (Coordinated Universal Time), but the "+24" appended to TZ is taken in relation to CUT and not local time. For me, the "+24" only moves the time back 19 hours. After 7:00 p.m. I no longer get yesterday's date.
For a full description of the TZ variable, see [], (or any of many other sights).
Reading this will make several other pitfalls inherent in the TZ trick obvious.
So, the question is, who can come up with the simplest technique to correctly adjust TZ to get yesterday's date?
It needs to work for any legal value of TZ, and not be harder that directly calculating yesterdays's date. Any volunteers?
$ date
Thu Oct 3 19:30:00 CDT 2002
$ TZ="$TZ+24" date
Thu Oct 3 00:30:17 CDT 2002
As you can see, appending "+24" to TZ did not yield yesterday's date. Why? because of where I am: the USA Central Timezone (in daylight savings time), as is indicated by the "CDT". Between May and October we are 5 hours behind CUT (Coordinated Universal Time), but the "+24" appended to TZ is taken in relation to CUT and not local time. For me, the "+24" only moves the time back 19 hours. After 7:00 p.m. I no longer get yesterday's date.
For a full description of the TZ variable, see [], (or any of many other sights).
Reading this will make several other pitfalls inherent in the TZ trick obvious.
So, the question is, who can come up with the simplest technique to correctly adjust TZ to get yesterday's date?
It needs to work for any legal value of TZ, and not be harder that directly calculating yesterdays's date. Any volunteers?