In the life of a developer, keystrokes matter, and “he/she who dies with the least keystrokes wins”.😃

So it can be frustrating when every time you want to enter a date and you want to make sure you are not beholden to the whim of the session NLS settings , then you need to specify

  • The TO_DATE function, and
  • Your date literal, and
  • The format mask

I just wanted a damn date and here I am typing in:


SQL> select to_date('25-DEC-2024','DD-MON-YYYY') from dual;

TO_DATE('
---------
25-DEC-24

But there is an easier way, one I’ve been using for as long as I remember. As long as you adopt the ISO standard (Please don’t ask me what particular ISO number it is, it’s just the “ISO standard” OK? 😃) then you can construct dates and timestamps much more easily


SQL> select date '2024-12-25' from dual;

DATE'2024
---------
25-DEC-24

SQL> select timestamp '2024-12-25 13:00:00' from dual;

TIMESTAMP'2024-12-2513:00:00'
----------------------------------------------------------------
25-DEC-24 01.00.00.000000000 PM

Ho Ho Ho… Merry Christmas!

4 responses to “Kris Kringle the Database – The Lazy Date”

  1. Why does not Oracle have ISO as the default when the database is created?

  2. ISO 8601 date format YYYY-MM-DD makes so much sense on a computer for collation.

    The international conventional date format DD/MM/YYYY at least is a logically reversed version but where the heck did the US date format MM/DD/YYYY come from?

    1. As per Batman: “Some people just want to watch the world burn” 🙂

  3. thanks, nice one

Leave a reply to JAYT22 Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Trending