Pages

Social Icons

Tuesday 28 January 2014

Get Current time zone time in SQL

Hi,

Below query will give the time according to time zone

DECLARE @TIMZONE VARCHAR(6)
DECLARE @USERTIMZONE VARCHAR(50) = 'HAWAIIAN STANDARD TIME'

SELECT @TIMZONE = CASE @USERTIMZONE
WHEN 'CENTRAL STANDARD TIME' THEN '-06:00'
WHEN 'EASTERN STANDARD TIME' THEN '-05:00'
WHEN 'HAWAIIAN STANDARD TIME' THEN '-10:00'
WHEN 'MOUNTAIN STANDARD TIME' THEN '-07:00'
WHEN 'PACIFIC STANDARD TIME' THEN '-08:00' END

SELECT CAST(SWITCHOFFSET(TODATETIMEOFFSET(GETUTCDATE(), '+00:00'),@TIMZONE) AS DATE)

Thanks,
RS

No comments:

Post a Comment