Convert special String into Date in H2

牧云@^-^@ 提交于 2020-06-12 06:40:48

问题


There is a SQL function from Oracle to_date('26 Jul 2016, 05:15:58 AM','DD Mon YYYY, HH:MI:SS AM'), and it throws exception "Illegal pattern character 'o'" in H2.

How shall I change it to make it work in H2?


回答1:


The equivalent function of TO_DATE() in H2 is PARSEDATETIME().

This is how you should use it with your sample data:

PARSEDATETIME('26 Jul 2016, 05:15:58 AM','dd MMM yyyy, hh:mm:ss a','en')

Be careful not to use HH:mm:ss otherwise the AM/PM detection will not work.




回答2:


Here is another example, integrating milliseconds:

The original value in Oracle is 13-APR-17 10.49.36.558000000 PM. First you need to get rid of the extra zeros and end up with 13-APR-17 10.49.36.558 PM then you can call

call PARSEDATETIME('13-APR-17 10.49.36.558000000 PM','dd-MMM-yy hh.mm.ss.SSS a','en');

Note the additional format parameter .SSS



来源:https://stackoverflow.com/questions/38586106/convert-special-string-into-date-in-h2

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