0

How to convert DateTimeOffset to DateTime?

I have tried using:

CONVERT(VARCHAR, 2018-03-02 12:00:00.0000000 -07:00, 120)

but the result is:

"2018-03-02 12:00:00 -07:00"

Ex: "2018-03-02 12:00:00.0000000 -07:00" to "2018-03-02 12:00:00"

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
K.Tom
  • 175
  • 1
  • 6
  • 16
  • Does this satisfy your needs? https://stackoverflow.com/questions/4953903/how-can-i-convert-a-sql-server-2008-datetimeoffset-to-a-datetime – Phil N DeBlanc Mar 05 '18 at 20:30

2 Answers2

0

According to the site I linked to above, and in my own testing, this works:

select select CONVERT(VARCHAR(19), CONVERT(DATETIME, SWITCHOFFSET('2018-03-02 12:00:00.0000000 -07:00', DATEPART(tz, SYSDATETIMEOFFSET()))),120)

That should do it!

Phil N DeBlanc
  • 398
  • 1
  • 13
0

Please use below conversion

declare @createdate datetimeoffset
set @createdate = '2018-03-02 12:00:00.0000000 -07:00'
select convert(datetimeoffset,CONVERT(datetime2, @createdate , 1))
rollstuhlfahrer
  • 3,988
  • 9
  • 25
  • 38
Sooraj
  • 1