Easwaran Paramasivam
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)?
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
CAST(CONVERT(datetime,
SWITCHOFFSET(CONVERT(datetimeoffset,
CreatedDtm),
REPLACE(DATENAME(TzOffset, SYSDATETIMEOFFSET()),'+','-') )) AS datetimeoffset)
Above code solved the issue.
ASKER
Thanks for your assistance
ASKER
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.