Akhilesh Mohare
Akhilesh Mohare

Reputation: 45

Format date in SQL for a specified format

I have recieved a particular date in the particular format 2015-06-13T21:49:13.395-07:00 which is inserted as varchar in database.

I want to convert this date into DATE format but am not getting the right formatter for the same

Upvotes: 0

Views: 154

Answers (2)

Lungisa Dotye
Lungisa Dotye

Reputation: 11

SELECT CAST(LEFT(REPLACE('2015-06-13T21:49:13.395-07:00','T',' '),23) AS DATETIME)

Upvotes: 0

Nick Krasnov
Nick Krasnov

Reputation: 27251

Use to_timestamp_tz() function to convert your string to a value of timestamp with timezone data type:

select to_timestamp_tz('2015-06-13T21:49:13.395-07:00'
                      , 'yyyy-mm-dd"T"hh24:mi:ss.ffTZH:TZM') as res
  from dual

Result:

RES                              
----------------------------------
13.06.15 21:49:13,395000000 -07:00

Upvotes: 5

Related Questions