samwell
samwell

Reputation: 2797

How to parse a string to a date, when the string has a character in it?

I'm trying to parse 2015-07-09T12:22:29 using TO_DATE using the following date format YYYY-MM-DDTHH:MI:SS, but I'm getting back the message as the date format is not recognized.

Upvotes: 1

Views: 137

Answers (2)

Andy Lester
Andy Lester

Reputation: 93636

You have to put the T in double quotes, like YYYY-MM-DD"T"HH:MI:SS.

select to_date( '2015-07-09T12:22:29', 'YYYY-MM-DD"T"HH:MI:SS' ) from dual;

TO_DATE('
---------
09-JUL-15

Here's the relevant documentation. (Thanks Alex)

Upvotes: 3

SQLMonger
SQLMonger

Reputation: 190

Be aware that the "T" in your date string indicates that it is in UTC format, not as standard date. Just ignoring the "T" character is not going to result in a correct datetime value, as you are not accounting for your local timezone.

Check out this post for some additional information:

Convert timestamp/date time from UTC to EST Oracle SQL

Upvotes: 1

Related Questions