Click here to Skip to main content
15,887,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My server save time in UCT not including Time Zones info in dateTime2. Server is in -7 GMT. I need to create an SQL which show records but converted at TimeZone for User (+1 GMT).

Let's imagine I have this record '2014-05-27 01:00:00' Should be displayed as '2014-05-27 09:00:00'

Using the following script I am not able to get the result desired. Could you please point me out the problem?

SQL
SELECT CONVERT(datetime,
    SWITCHOFFSET(CONVERT(datetimeoffset,
    '2014-05-27 01:00:00'),
    DATENAME(TzOffset, SYSDATETIMEOFFSET())))
Posted
Comments
Sunasara Imdadhusen 27-May-14 7:06am    
Have you search on Google?

Here is the code that might help you:

SELECT GETUTCDATE() 
SELECT DATEADD(HH,5,GETUTCDATE())


HH is the hours part. This can be the time zone difference. Get UTC date will give you the utc date
 
Share this answer
 
By this u can get current system time zone
-------------------------------------------
SQL
DECLARE @TimeZone VARCHAR(50)
EXEC MASTER.dbo.xp_regread 'HKEY_LOCAL_MACHINE',
'SYSTEM\CurrentControlSet\Control\TimeZoneInformation',
'TimeZoneKeyName',@TimeZone OUT

SELECT @TimeZone


Now Utc to Current time Zone
-------------------------
SQL
declare @offset decimal
set @offset= (select  DATEDIFF(minute,GETUTCDATE(), GETDATE()  ))
select dateadd(minute, @offset,GETUTCDATE())
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900