Monday, August 11, 2014

Showing date as MM/DD/YYYY in PL/SQL

Up until now, I've always left the date format for pulling data out of a clinic system as YYYY-MM-DD HH24:MI:SS when working with Toad for Oracle.  I don't always change the format but I'm finding that I'm having to change it more and more often after exporting to Excel to MM/DD/YYYY because the time of day isn't needed.


I tried to make it work on my own using the TO_DATE() function but kept getting the error...


ORA-01843: not a valid month


I'm believe it has to do with the leading zero at the beginning of most months.  Instead of using TO_DATE(table.field, 'MM/DD/YYYY') I found out that I should use TO_CHAR(table.field, 'MM/DD/YYYY').


What a simple fix. I was trying to make it harder than it was with the different combinations I was trying.


Yes I know this is kids stuff but when you have never had to convert a date format and it all of the sudden it would take a few manual steps away if you did, it's handy to document it somewhere.

No comments:

Post a Comment