0

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 .

2
  • 1
    Should be DD-MON-YY . . . Commented Jun 18, 2020 at 14:09
  • 1
    In addition to the other comments -- always, always, always use 4-digit years, not 2-digit. Does the term 'Y2k bug' ring any bells? Commented Jun 18, 2020 at 14:12

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.