Link to home
Create AccountLog in
Avatar of Easwaran Paramasivam
Easwaran ParamasivamFlag for India

asked on

How to convert existing datetime into UTC format?

Hi Experts,

  In my table tPostTran there was a column called PostedDtm. The data type of it was DateTime. Now the DB is being upgraded. The posteddtm column's data type is modified as DateTimeOffset(2). The column already contained data. I would like to modify the existing date value to UTC format. How to achieve this?

  What is the difference between datetime and datetimeoffset (2)?
ASKER CERTIFIED SOLUTION
Avatar of Patrick Bogers
Patrick Bogers
Flag of Netherlands image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Easwaran Paramasivam

ASKER

Thanks. But in given link datetimeoffset is converted into UTC format. But I would like to perform from datetime field.

Say for example below is my format:

declare @createdon DateTime
set @createdon = '2013-03-08 12:35:41.807'


I would like to get UTC in datetimeoffset (2) format. Please assist.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
 CAST(CONVERT(datetime, 
SWITCHOFFSET(CONVERT(datetimeoffset, 
CreatedDtm), 
REPLACE(DATENAME(TzOffset, SYSDATETIMEOFFSET()),'+','-') )) AS datetimeoffset)

Open in new window


Above code solved the issue.
Thanks for your assistance