Results 1 to 2 of 2
  1. #1
    Join Date
    May 2002
    Location
    Boca Raton, FL
    Posts
    5

    Unanswered: Local Time to UTC Time?

    I have a column in a database that holds a GETDATE() value. I need to convert that to the UTC equivelent. How can i go about doing this? Going forward i am using GETUTCDATE(), but i need to convert some data fields from the date thats there to its UTC equivelent. (SQL 2000)

    Thanks!

  2. #2
    Join Date
    Aug 2002
    Location
    Scotland
    Posts
    1,578
    -- 1994-11-05T08:15:30-05:00
    -- 1994-11-05T13:15:30Z

    DECLARE @UTC VARCHAR(25)
    DECLARE @Date DATETIME
    DECLARE @HH SMALLINT
    DECLARE @MM SMALLINT

    SET @UTC = '1994-11-05T08:15:30-05:00'
    -- SET @UTC = '1994-11-05T13:15:30Z'

    SET @Date = LEFT(@UTC, 10) + SPACE(1) + SUBSTRING(@UTC, 12, 8)

    IF RIGHT(RTRIM(LTRIM(@UTC)), 1) = 'Z'
    BEGIN
    SELECT @Date
    END
    ELSE
    BEGIN
    SET @HH = -1 * SUBSTRING(@UTC, 20, 3)
    SET @MM = -1 * SUBSTRING(@UTC, 20, 1) + SUBSTRING(@UTC, 24, 2)

    SET @Date = DATEADD(HOUR, @HH, @Date)
    SET @Date = DATEADD(MINUTE, @MM, @Date)

    SELECT @Date
    END
    --Satya SKJ
    Microsoft SQL Server MVP
    [IMG]http://sqlserver-qa.net/google_bart.gif[/IMG]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •