IBM i Global

 View Only
Expand all | Collapse all

Get UTC timestamp from local timestamp

  • 1.  Get UTC timestamp from local timestamp

    Posted Wed April 27, 2022 03:58 AM
    Edited by Paolo Salvatore Wed April 27, 2022 05:37 AM
    Hi, 

    I've to convert a timestamp column in a table from local timestamp to UTC timestamp, I found current timezone so I think about something like this:

    Values Timestamp('2022-04-26-10.00.01.123456') - hour(current timezone) hours;​

     

    Image I've stored in my table a timestamp like the example, I could make the expression above, but it depends on day light saving time. the below expression isn't correct if I found a value between november to march.

    Any ideas?

    Many thanks



    ------------------------------
    Paolo Salvatore
    ------------------------------


  • 2.  RE: Get UTC timestamp from local timestamp

    IBM Champion
    Posted Wed April 27, 2022 07:52 AM
    I think you'd be better off writing a UDF to handle that.  This way you could check the date range too.  You'd also have to decide just how far back you want to go.  Like some years ago when they changed the start/stop dates of DST.  Or the US government strongly considering staying on DST year around.
    I do like your starting point.

    ------------------------------
    Robert Berendt
    ------------------------------