convert datetime in utc seconds

  • Hi guys,

    Do you know how to convert a datetime to UTC seconds:

    eg: nov 17, 2005 21:00:00

    UTC in seconds: 1132261200

     

     

  • UTC Seconds, also called Epoch Start Seconds, is the number of seconds since January 1st, 1970, with the local date and time adjusted to the UTC timezone.

    declare @EpochStartTs datetime

    , @GregorianTs datetime

    -- date and time format is ODBC

    set @EpochStartTs = { ts '1970-01-01 00:00:00'}

    -- nov 17, 2005 21:00:00 in the Central Time Zone (Chicago, Illinois)

    set @GregorianTs = { ts '2005-11-17 21:00:00'}

    select datediff(ss,@EpochStartTs,@GregorianTs) as UTCSeconds_London

    , datediff(ss,@EpochStartTs,@GregorianTs)

    -- Add the timezone difference

    + datediff(ss,GETUTCDATE() , current_timestamp) as UTCSeconds_Chicago

    SQL = Scarcely Qualifies as a Language

  • select convert(bigint, datediff(dd, '1970-01-01', GETUTCDATE()))*24*3600 + datediff(ss, dateadd(dd, datediff(dd, 0, GETUTCDATE()), 0), GETUTCDATE())

    _____________
    Code for TallyGenerator

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply