Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to display days in "rd", "th", "nd", and "st" format in Oracle SQL Developer?

guys,

I have to display the day of tomorrow in the format: January 10th of year 2019.
I created this query:

SELECT TO_CHAR((SYSDATE + 1),'Month DD (ddspth) "of year" YYYY') AS tomorrow FROM DUAL;

The output is:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

May       23 (twenty-third) of year 2023

How can I get the output in the desired format?

Thanks in advance.

>Solution :

Don’t spell the word out; and use FM to suppress blank padding:

SELECT TO_CHAR((SYSDATE + 1),'FMMonth ddth "of year" YYYY') AS tomorrow FROM DUAL;

May 24th of year 2022

db<>fiddle demo.

Month names are NLS-sensitive, so someone running this in a session with a different date language set will see something else – which you can override. The th will be in English anyway, as will your character literal part. You might want to force the month names to English to match. That might be beyond the requirements for this exercise but I’ve included how to to it in the db<>fiddle.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading