Oracle to_date with p.m./a.m

Abel Juan Rodríguez picture Abel Juan Rodríguez · Dec 3, 2014 · Viewed 35.5k times · Source

I need to convert a string into a Date in oracle.

The format of the string is like this:

'08/11/1999 05:45:00 p.m.'

But the last position can change p.m or a.m. I tried to do some like:

to_date('08/11/1999 05:45:00 p.m.', 'dd/mm/yyyy hh:mi:ss a.m./p.m.')

to_date('08/11/1999 05:45:00 p.m.', 'dd/mm/yyyy hh:mi:ss am/pm')

But return me an error ORA-01855 : AM/A.M. or PM/P.M. required... any idea ?

Answer

Tony Andrews picture Tony Andrews · Dec 3, 2014

Try this:

to_date
  ( '08/11/1999 05:45:00 p.m.'
  , 'dd/mm/yyyy hh:mi:ss a.m.'
  , 'nls_date_language=american'
  )

It seems that "a.m." and "p.m." rather than "am" and "pm" require nls_date_language to be set to "american".