Oracle to_date with p.m./a.m

给你一囗甜甜゛ 提交于 2019-12-02 07:28:11

问题


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 ?


回答1:


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".




回答2:


to convert time for am and pm, just give a.m. like below

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

hope this might help. please refer https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions183.htm



来源:https://stackoverflow.com/questions/27269903/oracle-to-date-with-p-m-a-m

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!