Oracle's default date format is YYYY-MM-DD, Why?
The question is based on a common misconception that a DATE
data-type has a format in the database; it does not.
In Oracle, a DATE
is a binary data-type consisting of 7 bytes representing: century, year-of-century, month, day, hour, minute and second. It ALWAYS has those 7 components and it is NEVER stored in any particular human-readable format.
Why those 7 components and not just year, month and day like an ANSI-standard DATE
?
Oracle's DATE
data type predates the ANSI standard (by about 7 years) and has maintained backwards compatibility with previous database versions.
Why does Oracle's default date format appear to be YYYY-MM-DD?
As stated, it is not, it is a 7-byte binary value without a format. When the client application (i.e. SQL*Plus, SQL Developer, Java, C#, etc.) requests a DATE
then the database will send that client the 7-byte DATE
value; however, unformatted binary data is not particularly useful to you, the user, so the client application chooses how to format the date so that it is meaningful to you, the user, and that means it has to convert it from binary to a formatted value.
This means that any implicit formatting of a DATE
is done by the client application and NOT by the database. The database will ALWAYS work with the raw bytes when it is handling dates.
Why does the client application's default date format appear to be YYYY-MM-DD?
This depends on the client application you are using. However, in most cases, you can change the preferences for the client application and set your own format model for DATE
s. You will need to refer to the documentation for that client application (as there are many different clients and they will all have a different way to set the default DATE
format).
Let us assume that you are using an Oracle client application (such as SQL*Plus, SQL Developer or SQLCl), why does the client application's default date format appear to be YYYY-MM-DD?
This is not entirely true.
- Those clients do not use
YYYY-MM-DD
as the format model but instead default to use the database's NLS_DATE_FORMAT
as the client's format model for displaying dates (although they can be overridden with in the client-side configuration).
- The database's
NLS_DATE_FORMAT
is the format that Oracle will use to implicitly cast strings-to-dates and dates-to-strings (i.e. if you use TO_DATE(string_column)
or TO_CHAR(date_column)
without specifying a format model in the second argument then it will use the NLS_DATE_FORMAT
). However, it is worth repeating that when a client application requests a DATE
then the database does not perform any modifications to the binary data it holds and just sends the client the 7-byte value and lets the client application do whatever it wants with the entire DATE
(including the time component).
- The
NLS_DATE_FORMAT
is based on the NLS_TERRITORY
parameter and therefore the default NLS_DATE_FORMAT
varies throughout the world; out-of-the-box, a database instance only has the format RRRR-MM-DD
when the territory is set to Bulgaria or Sweden (however, the DBA can override the defaults during database creation).
- So it appears that either: you are in Bulgaria or Sweden and the default is that because Oracle has determined that the most prevalently used date format in your country is
RRRR-MM-DD
and set that as the default for your territory; or that your DBA has set the default to YYYY-MM-DD
(possibly because it is the ISO8601 standard for formatting a date).
So, the answer to your question is:
- You appear to be using a client application that implicitly applies a format to dates based on the database
NLS_DATE_FORMAT
session parameter and the NLS_DATE_FORMAT
was set either implicitly based on the NLS_TERRITORY
chosen during database creation or explicitly by the DBA.
- If you want to change how the client application formats a
DATE
then change the default settings (either on the client or, if the client takes the default from the database then change the database).
NLS_TERRITORY
session/database parameter so setting up servers in different locations around the world (using their local settings) can have different defaults. The Philippines hasMM/DD/RRRR
while Israel isDD-MON-RRRR
and Sweden isRRRR-MM-DD
soTO_DATE( '01-02-03' )
would give different results in each of those territories. – WindowpaneYYYY-MM-DD
(I wish it was), so the question is misguided from the start, although it's true that the various locale-specific defaults don't include the time. If this was a new post I'd vote to close as opinion-based and not a programming question. – Microbarograph