SQL Server當地時光和UTC時光的互相轉換完成代碼。本站提示廣大學習愛好者:(SQL Server當地時光和UTC時光的互相轉換完成代碼)文章只能為提供參考,不一定能成為您想要的結果。以下是SQL Server當地時光和UTC時光的互相轉換完成代碼正文
DECLARE @LocalDate DATETIME,
@UTCDate DATETIME,
@LocalDate2 DATETIME
SET @LocalDate = GETDATE()
SET @UTCDate = DATEADD(hour, DATEDIFF(hour,GETDATE(),GETUTCDATE()), @LocalDate)
SET @LocalDate2 = DATEADD(hour, DATEDIFF(hour,GETUTCDATE(),GETDATE()), @UTCDate)
SELECT '1. Now' [Now], @LocalDate [DateTime]
UNION
SELECT '2. UTC', @UTCDate
UNION
SELECT '3. Now again', @LocalDate2