1

The below command is used for getting the yerterdays date in Unix Ksh on HP UX

DATE_STAMP=`TZ=CST+24 date +%m/%d/%Y` 

Can somebody let me know what does "CST + 24 date " in above command do?

j0k
  • 22,600
  • 28
  • 79
  • 90
UnixQue
  • 13
  • 1
  • 1
  • 3
  • If this is the same `date` command which is part of the GNU coreutils, you can get yesterdays date using `date --date=yesterday`. – Noufal Ibrahim Jun 30 '11 at 17:41
  • @Noufal Ibrahim I don't see that option on HPUX. – Praveen Lobo Jun 30 '11 at 18:11
  • This is not part of GNU coreutils so i cannot use that command – UnixQue Jun 30 '11 at 18:15
  • Oh well... was worth a shot. The HP-UX machines I worked with had GNU coreutils installed somewhere non standard. Maybe yours does too? – Noufal Ibrahim Jun 30 '11 at 18:15
  • i tried running the command but i got "--date=yesterday: not found" error after execution so looks like it is not installed in my machine – UnixQue Jun 30 '11 at 18:28
  • Note that this command will return an correct date "only" for 99.9772 % of the cases. Expressed differently, it will fail twice a year during one hour due to the DST changes. – jlliagre Aug 07 '13 at 14:35

3 Answers3

2

That command sets the timezone to CST+24 and returns the date in that timezone.

if you are looking for a command to find out yesterday's date, you are better of using the TZ trick esp. if you are in a timezone that observes DST.

use perl one liner instead.

#this takes local time and substracts a day(24*60*60 seconds) and formats the time.
echo `perl -e 'use POSIX; print strftime "%m/%d/%Y%", localtime time-86400;'` 

Just a guess on your command - since its yesterday at CST+24 timezone the command returns yesterday's date and if you use CST-24, it retunrs tomorrow's date since the date translates to tomorrows date at CST-24 timezone.

Praveen Lobo
  • 6,956
  • 2
  • 28
  • 40
1

VARIABLE=VALUE COMMAND means that you set the environment variable VARIABLE to VALUE but not persistent but only for the executed command COMMAND.

In your example that means: Execute the date command with the environment variable TZ set to CST+24 (which is Central Standard Time plus 24 hours).

bmk
  • 13,849
  • 5
  • 37
  • 46
-1

Check out this page http://www.kodkast.com/blogs/unix-shell-scripting/how-to-get-yesterdays-date where you can find out yesterday's date as well as any other previous date in unix shell scripting.

  • Your answer is barely a link to another site which is not appropriate with SO. Moreover, the page you linked to doesn't apply to the question. – jlliagre Oct 21 '13 at 02:59