Oracle to_date with pm/am

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27269903/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 00:41:36  来源:igfitidea点击:

Oracle to_date with p.m./a.m

oracleto-date

提问by Abel Juan Rodríguez

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

我需要在 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:

但是最后一个位置可以改变 pm 或者我尝试做一些类似的事情:

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 ?

但是给我一个错误 ORA-01855 : AM/AM 或 PM/PM 需要......知道吗?

回答by Tony Andrews

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_languageto be set to "american".

似乎“am”和“pm”而不是“am”和“pm”需要nls_date_language设置为“american”。

回答by Exhausted

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

将时间转换为amand pma.m.就像下面一样

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://docs.oracle.com/cd/B19306_01/server.102/b14200/functions183.htm