Platus
Platus

Reputation: 1507

SQL Server equivalent of Oracle to_timestamp_tz()

I would like to know how I can translate this Oracle line into SQL Server code:

to_timestamp_tz('18/08/14 09:43:29,262000000 +02:00','DD/MM/RR HH24:MI:SSXFF TZR')

Upvotes: 2

Views: 760

Answers (1)

SqlZim
SqlZim

Reputation: 38063

You can convert() to datetimeoffset() by replacing the comma with a period, and specifying a style that matches day first (if not already implicitly set by session settings and/or session language settings):

declare @str varchar(40) = '18/08/14 09:43:29,262000000 +02:00';
select convert(datetimeoffset(7),replace(@str,',','.'),4)

Or setting set dateformat dmy:

set dateformat dmy;
select convert(datetimeoffset(7),replace(@str,',','.'))

rextester demo: http://rextester.com/GSGL61143

Upvotes: 1

Related Questions