ali amani
ali amani

Reputation: 35

problem with using to_date in oracle query

i simply wanna change a string to a date format using to_date SELECT TO_DATE('20-APR-20 09.50.06 AM' , 'DD-MOM-YY HH24:MI:SS AM') FROM DUAL;

and also i want to change to 24 format

when i run this i get the ORA-01821: date format not recognized error .

Upvotes: 0

Views: 133

Answers (2)

monika
monika

Reputation: 67

The correct format is

SELECT TO_CHAR(TO_DATE('20/APR/20 09.50.06 AM' , 'DD-MON-YY HH:MI:SS AM'),'DD-MON-YY HH:MI:SS AM') FROM DUAL;

Upvotes: 1

Gordon Linoff
Gordon Linoff

Reputation: 1269783

The correct format for converting your string to a date is:

SELECT TO_DATE('20-APR-20 09.50.06 AM' , 'DD-MON-YY HH.MI.SS AM')
FROM DUAL;

If you want it as a string, then you can use TO_CHAR() after converting to a date. That said, I recommend keeping the value as a date.

Upvotes: 2

Related Questions