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!-- 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
No comments:
Post a Comment