DECLARE @convertedUTC datetime, @convertedLocal datetime
SELECT DATEADD(
HOUR, -- Add a number of hours equal to
DateDiff(HOUR, GETDATE(), GETUTCDATE()), -- the difference of UTC-MyTime
GetDate() -- to MyTime
)
SELECT @convertedUTC = DATEADD(HOUR,DateDiff(HOUR, GETDATE(), GETUTCDATE()),GetDate()) --Assign the above to a var
SELECT DATEADD(
HOUR, -- Add a number of hours equal to
DateDiff(HOUR, GETUTCDATE(),GETDATE()), -- the difference of MyTime-UTC
@convertedUTC -- to MyTime
)
SELECT @convertedLocal = DATEADD(HOUR,DateDiff(HOUR, GETUTCDATE(),GETDATE()),GetDate()) --Assign the above to a var
/* Do our converted dates match the real dates? */
DECLARE @realUTC datetime = (SELECT GETUTCDATE())
DECLARE @realLocal datetime = (SELECT GetDate())
SELECT 'REAL:', @realUTC AS 'UTC', @realLocal AS 'Local'
UNION
SELECT 'CONVERTED:', @convertedUTC AS 'UTC', @convertedLocal AS 'Local'
क्या आपको डीएसटी संक्रमण के दौरान समय से निपटना होगा (जहां दो यूटीसी मूल्य एक स्थानीय समय के लिए वैध परिणाम हो सकते हैं)? –