In SQL server you can get the local datetime UTC time . Convert it to different TimeZone:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
DECLARE @CurrentDateTime DATETIME = GETDATE(); DECLARE @CurrentUTC DATETIME = GETUTCDATE(); DECLARE @TimeZoneLocal VARCHAR(50) EXEC MASTER.dbo.xp_regread 'HKEY_LOCAL_MACHINE', 'SYSTEM\CurrentControlSet\Control\TimeZoneInformation','TimeZoneKeyName',@TimeZoneLocal OUT SELECT @TimeZoneLocal AS ServerTimeZone, GETDATE() AS ServerCurrentDT, GETUTCDATE() AS 'GetUTCDATE', GETDATE() AT TIME ZONE 'UTC' AS 'UTC', GETUTCDATE() AT TIME ZONE 'UTC' AT TIME ZONE 'Eastern Standard Time' AS 'to EST', GETUTCDATE() AT TIME ZONE 'UTC' AT TIME ZONE 'Pacific Standard Time' AS 'to PST', GETUTCDATE() AT TIME ZONE 'UTC' AT TIME ZONE 'Central European Standard Time' AS 'to CET', GETUTCDATE() AT TIME ZONE 'UTC' AT TIME ZONE'India Standard Time' AS 'to IST'; |
Convert a local datetime or the server local time to different timezone:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
DECLARE @OneDatetime DATETIME = '2024-07-05 16:21:00.000'; -- Replace with your datetime value in Local server datetime Set @OneDatetime = GETDATE() -- you can comment out if you have spec datetime for local server in previous line DECLARE @TimeZone VARCHAR(50) EXEC MASTER.dbo.xp_regread 'HKEY_LOCAL_MACHINE', 'SYSTEM\CurrentControlSet\Control\TimeZoneInformation','TimeZoneKeyName',@TimeZone OUT SELECT @OneDatetime AS OneDatetime , @OneDatetime AT TIME ZONE @TimeZone AS 'Local_OneDatetime' , Convert(DATETIME, @OneDatetime AT TIME ZONE @TimeZone AT TIME ZONE 'Pacific Standard Time')AS 'to PST', Convert(DATETIME, @OneDatetime AT TIME ZONE @TimeZone AT TIME ZONE 'Eastern Standard Time') AS 'to EST', Convert(DATETIME, @OneDatetime AT TIME ZONE @TimeZone AT TIME ZONE 'UTC' ) AS 'to UTC', Convert(DATETIME, @OneDatetime AT TIME ZONE @TimeZone AT TIME ZONE 'Central European Standard Time') AS 'to CET', Convert(DATETIME, @OneDatetime AT TIME ZONE @TimeZone AT TIME ZONE 'India Standard Time') AS 'to IST', @TimeZone AS ServerTimeZone, GETDATE() AS Server_Currrent_GetDate, @OneDatetime AT TIME ZONE @TimeZone AS 'Server_current_offset' |
Convert UTC datetime or the server UTC time to different timezone:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
DECLARE @UTCOneDatetime DATETIME = '2024-07-05 20:21:00'; -- Replace with your datetime value in Local server datetime Set @UTCOneDatetime = GETUTCDATE() -- yo can comment out if you have UTC datetime DECLARE @TimeZone VARCHAR(50) EXEC MASTER.dbo.xp_regread 'HKEY_LOCAL_MACHINE', 'SYSTEM\CurrentControlSet\Control\TimeZoneInformation','TimeZoneKeyName',@TimeZone OUT SELECT @UTCOneDatetime AS UTCOneDatetime , --@UTCOneDatetime AT TIME ZONE @TimeZone AS 'UTC_OneDatetime' , Convert(DATETIME, @UTCOneDatetime AT TIME ZONE 'UTC' AT TIME ZONE 'Pacific Standard Time')AS 'to PST', Convert(DATETIME, @UTCOneDatetime AT TIME ZONE 'UTC' AT TIME ZONE 'Eastern Standard Time') AS 'to EST', Convert(DATETIME, @UTCOneDatetime AT TIME ZONE 'UTC' AT TIME ZONE 'UTC' ) AS 'to UTC', Convert(DATETIME, @UTCOneDatetime AT TIME ZONE 'UTC' AT TIME ZONE 'Central European Standard Time') AS 'to CET', Convert(DATETIME, @UTCOneDatetime AT TIME ZONE 'UTC' AT TIME ZONE 'India Standard Time') AS 'to IST', Convert(DATETIME, @UTCOneDatetime AT TIME ZONE 'UTC' AT TIME ZONE 'UTC') AS UTC, Convert(DATETIME, @UTCOneDatetime AT TIME ZONE 'UTC' AT TIME ZONE @TimeZone) AS '--> To_LocalServerTime <--', @TimeZone AS ServerTimeZone, GETDATE() AS 'Server_Current_GetDate', GETUTCDATE() AS 'Server_Current_GetUTCDate', GETUTCDATE() AT TIME ZONE 'UTC' AT TIME ZONE @TimeZone AS 'Server_Current_offset' |
or all in one:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
-- Mehet egyben /**** current date time on the server *****/ DECLARE @CurrentDateTime DATETIME = GETDATE(); DECLARE @CurrentUTC DATETIME = GETUTCDATE(); DECLARE @TimeZoneLocal VARCHAR(50) EXEC MASTER.dbo.xp_regread 'HKEY_LOCAL_MACHINE', 'SYSTEM\CurrentControlSet\Control\TimeZoneInformation','TimeZoneKeyName',@TimeZoneLocal OUT -- SELECT @TimeZoneLocal AS ServerTimeZone, GETDATE() AS ServerCurrentDT, GETUTCDATE() AS 'GetUTCDATE', GETDATE() AT TIME ZONE 'UTC' AS 'UTC', GETUTCDATE() AT TIME ZONE 'UTC' AT TIME ZONE 'Central European Standard Time' AS 'to CET', GETUTCDATE() AT TIME ZONE 'UTC' AT TIME ZONE'India Standard Time' AS 'to IST'; ---------------------------------------- -- SELECT * FROM sys.time_zone_info; ---------------------------------------- /**** specific date time on the server *****/ DECLARE @OneDatetime DATETIME = '2024-07-05 16:21:00.000'; -- Replace with your datetime value in Local server datetime Set @OneDatetime = GETDATE() -- you can comment out if you have spec datetime for local server DECLARE @TimeZone VARCHAR(50) EXEC MASTER.dbo.xp_regread 'HKEY_LOCAL_MACHINE', 'SYSTEM\CurrentControlSet\Control\TimeZoneInformation','TimeZoneKeyName',@TimeZone OUT SELECT @OneDatetime AS OneDatetime , @OneDatetime AT TIME ZONE @TimeZone AS 'Local_OneDatetime' , Convert(DATETIME, @OneDatetime AT TIME ZONE @TimeZone AT TIME ZONE 'Pacific Standard Time')AS 'to PST', Convert(DATETIME, @OneDatetime AT TIME ZONE @TimeZone AT TIME ZONE 'Eastern Standard Time') AS 'to EST', Convert(DATETIME, @OneDatetime AT TIME ZONE @TimeZone AT TIME ZONE 'UTC' ) AS 'to UTC', Convert(DATETIME, @OneDatetime AT TIME ZONE @TimeZone AT TIME ZONE 'Central European Standard Time') AS 'to CET', Convert(DATETIME, @OneDatetime AT TIME ZONE @TimeZone AT TIME ZONE 'India Standard Time') AS 'to IST', @TimeZone AS ServerTimeZone, GETDATE() AS Server_Currrent_GetDate, @OneDatetime AT TIME ZONE @TimeZone AS 'Server_current_offset' /**** specific UTC date time on the server *****/ DECLARE @UTCOneDatetime DATETIME = '2024-07-05 20:21:00'; -- Replace with your datetime value in Local server datetime Set @UTCOneDatetime = GETUTCDATE() -- yo can comment out if you have UTC datetime --DECLARE @TimeZone VARCHAR(50) EXEC MASTER.dbo.xp_regread 'HKEY_LOCAL_MACHINE', 'SYSTEM\CurrentControlSet\Control\TimeZoneInformation','TimeZoneKeyName',@TimeZone OUT SELECT @UTCOneDatetime AS UTCOneDatetime , --@UTCOneDatetime AT TIME ZONE @TimeZone AS 'UTC_OneDatetime' , Convert(DATETIME, @UTCOneDatetime AT TIME ZONE 'UTC' AT TIME ZONE 'Pacific Standard Time')AS 'to PST', Convert(DATETIME, @UTCOneDatetime AT TIME ZONE 'UTC' AT TIME ZONE 'Eastern Standard Time') AS 'to EST', Convert(DATETIME, @UTCOneDatetime AT TIME ZONE 'UTC' AT TIME ZONE 'UTC' ) AS 'to UTC', Convert(DATETIME, @UTCOneDatetime AT TIME ZONE 'UTC' AT TIME ZONE 'Central European Standard Time') AS 'to CET', Convert(DATETIME, @UTCOneDatetime AT TIME ZONE 'UTC' AT TIME ZONE 'India Standard Time') AS 'to IST', Convert(DATETIME, @UTCOneDatetime AT TIME ZONE 'UTC' AT TIME ZONE 'UTC') AS UTC, Convert(DATETIME, @UTCOneDatetime AT TIME ZONE 'UTC' AT TIME ZONE @TimeZone) AS '--> To_LocalServerTime <--', @TimeZone AS ServerTimeZone, GETDATE() AS 'Server_Current_GetDate', GETUTCDATE() AS 'Server_Current_GetUTCDate', GETUTCDATE() AT TIME ZONE 'UTC' AT TIME ZONE @TimeZone AS 'Server_Current_offset' |
TimeZones
1 |
SELECT * FROM sys.time_zone_info; |
UTC datetime to local server datetime (you can replace the datetime with a column):
1 |
SELECT SWITCHOFFSET( '2025-05-27 18:00', DATENAME(TzOffset, SYSDATETIMEOFFSET())) AS localServerTime |