2

What format would you use to convert this CHAR value into a date?

Apr  9 1996  2:11:00:000PM


ie. select to_date('Apr  9 1996  2:11:00:000PM','???') from dual;

Has anyone found a good reference because all the ones I see expect that the hour has a preceding 0 to start with.

toop
  • 10,834
  • 24
  • 66
  • 87

3 Answers3

4

Here is the sample with your date string.

select to_date(
to_char(to_timestamp('Apr 9 1996 2:11:00:000PM','MON DD YYYY hh:mi:ss:FF3PM'),'YYYY-MM-DD HH:MI:SS AM'),
'YYYY-MM-DD HH:MI:SS AM')
from dual;

Hope it works.

Deb
  • 981
  • 13
  • 39
2

First: TO_DATE doesn't support fractional seconds, so you have to play around with TO_TIMESTAMP

Second: you have to use oracle's formats you can find a table of valid values here

At first glance a format like 'MON DD YYYY HH:MI:SS:FF3 AM' should work

Edit: too low on coffeine today, forgot the AM ^^ Sorry

BigMike
  • 6,683
  • 1
  • 23
  • 24
1

This might work (untested):

'Mon  dd YYYY   HH:MI:SS   AM'
wallyk
  • 56,922
  • 16
  • 83
  • 148