Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to convert YYYYMMDD to DD-Mon-YYYY in oracle?

I am trying to convert the date from YYYYMMDD to DD-Mon-YYYY in Oracle, but to_char or to_Date is not working. Can you please advise?

select to_date(20150324,'DD-Mon-YY') from dual; select to_char(20150324,'DD-Mon-YY') from dual;

I get an error message saying: - ORA-01861: literal does not match format string

like image 984
Avinash Ganesh Avatar asked Oct 15 '25 13:10

Avinash Ganesh


1 Answers

Use this combination of to_char and to_date:

select to_char (to_date('20150324','YYYYMMDD'), 'DD-Mon-YY') from dual;

Your mistake was, that you used the wrong date pattern. Additionally it's recommended to add'', though it worked without them in this case.

Check this Fiddle.

like image 106
Trinimon Avatar answered Oct 18 '25 05:10

Trinimon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!