Search code examples
sql-serverdatabasedatetimetsqltdatetime-conversion

How to convert datetime fileds to UTC Datetime for existing data in the database?


How can I change the Datetime values for the existing data to UTC Time? Is any inbuilt SQL qry available to change?

Eg. Existing Data in the table

CreatedON
2013-03-01 08:12:00.000
2013-03-01 13:15:18.000
2013-03-01 13:10:00.000

Need to convert this data to UTC time which is recorded as GMT Time during creation. Any suggestions will be helpful


Solution

  • try this:

    declare @a datetime 
    set @a='2013-03-01 08:12:00.000'
    
    select  DateAdd(s,DateDiff(s, getdate(),getutcdate()),@a )