问题
Can anyone help me how to convert 2016-07-01 01:12:22 PM to 2016-07-01 13:12:22 in PL/SQL? I used the following but no luck.
SELECT TO_TIMESTAMP ('08-FEB-19 06.41.41.000000 PM', 'DD-Mon-RR HH24:MI:SS.FF')
FROM dual
I expect: 08-FEB-19 18.41.41.000000
I get the following error:
ORA-01830: date format picture ends before converting the entire input string
回答1:
Your current timestamp makes no sense, because it specifies the time as 18 hours, which is 6pm, but then it also specifies the AM meridian indicator, which means earlier than noon. So, you may remove the AM from your TO_TIMESTAMP pattern:
SELECT TO_TIMESTAMP ('08-FEB-19 18.41.41.000000', 'DD-Mon-RR HH24.MI.SS.FF')
FROM dual;
08-FEB-19 06.41.41.000000000 PM
Note that there is really no such thing as 12 or 24 hour format timestamp internally in Oracle. Rather, if you want to view your Oracle timestamp in 24 hour format, you may do something like call TO_CHAR with an appropriate 24 hour format mask:
SELECT
TO_CHAR(TO_TIMESTAMP ('08-FEB-19 18.41.41.000000', 'DD-Mon-RR HH24.MI.SS.FF'),
'DD-Mon-RR HH24.MI.SS.FF') AS ts
FROM dual;
08-Feb-19 18.41.41.000000000
Demo
Edit:
If you wanted to convert a timestamp string with 12 hour time and an AM/PM component, we can try:
SELECT
TO_CHAR(
TO_TIMESTAMP ('08-FEB-19 06.41.41.000000 PM', 'DD-Mon-RR HH.MI.SS.FF PM'),
'DD-Mon-RR HH24.MI.SS.FF')
FROM dual;
来源:https://stackoverflow.com/questions/54586807/how-to-convert-2016-07-01-011222-pm-to-2016-07-01-131222-hour-format