TZ

  • Creator
    Topic
  • #53360
    Bob Schmid
    Participant

      Since daylight savings time…the TZ calculation in ksh does not “work”

      Todays date is 11/07/2012

      `TZ=$TZ+24 date +%Y%m%d` yields 20121107 ….when it should yield 20121105

      System date and time is correct: Wed Nov  7 11:33:35 EST 2012

      TZ = EST5EDT

      AIX 6.1.0.0

    Viewing 2 reply threads
    • Author
      Replies
      • #77420
        David Barr
        Participant

          It looks like you’re trying to get the date in a timezone that is 24 hours ahead of EST. I’m not sure why you’d want to do that, but I don’t think I’d expect the result to be a time two days ago.

          I think the intent of the + and – values in the TZ variable are to manually specify a real timezone relative to UTC, and the range would be between -12 and +14.

        • #77421
          Chris Williams
          Participant

            Bob,

            I’m not sure what you’re trying to accomplish with your calculation unless TZ is being manipulated prior to this line of code.

            1. TZ is set to the string “EST5EDT”. It means you are in the Eastern time zone, 5 hours offset from UTC/GMT and you observe Daylight Savings when you are in that part of the calendar. Portions of Indiana that don’t observe DST would use a different string.

            2. `TZ=$TZ+24` returns null.

            3. `date +%Y%m%d` is the standard date command with formatting information. Note the + is required for specifying format.

            Cheers.

          • #77422
            David Barr
            Participant

              Chris Williams wrote:


              2. `TZ=$TZ+24` returns null.

              Yes, but if you have a variable assignment before a command (date), then the variable assignment takes effect just for that command. So he’s trying to append +24 to the timezone when he runs the date command. I think he’s trying to get yesterday’s date.

              This is probably a more reliable way of doing the same thing:

              `perl -MPOSIX -e ‘print strftime (“%Y%m%d”, localtime(strftime (“%s”, localtime) – 86400))’`

          Viewing 2 reply threads
          • The forum ‘Operating Systems’ is closed to new topics and replies.