Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle's default date format is YYYY-MM-DD, WHY?

Oracle's default date format is YYYY-MM-DD. Which means if I do:

 select some_date from some_table 

...I lose the time portion of my date.

Yes, I know you can "fix" this with:

 alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss'; 

But seriously, why isn't the above the default? Especially in a DBMS where the two primary time-tracking data types (DATE and TIMESTAMP) both have a time component that includes (at least) accuracy down to 1 second.

like image 663
Aaron Fi Avatar asked Dec 03 '09 06:12

Aaron Fi


People also ask

What is default date format in Oracle?

Oracle stores dates in an internal numeric format representing the century, year, month, day, hours, minutes, seconds. The default date format is DD-MON-YY.

How do I change date format from YYYY MM DD in Oracle?

So you want: select To_date (date_value, 'yyyy-mm-dd') as date_value from table_x; Format is a quality of strings, not DATEs. Once you have converted your string to a DATE, is is stored in the same internal format as all the other DATEs.

What is the format of date datatype in Oracle?

The default date format for an Oracle date value is derived from the NLS_DATE_FORMAT and NLS_DATE_LANGUAGE initialization parameters. The date format in the example includes a two-digit number for the day of the month, an abbreviation of the month name, the last two digits of the year, and a 24-hour time designation.

What is the default format of date in Oracle How can I change my default date format?

Finally, you can change the default DATE format of Oracle from "DD-MON-YY" to something you like by issuing the following command in sqlplus: alter session set NLS_DATE_FORMAT='<my_format>'; The change is only valid for the current sqlplus session.


2 Answers

Are you sure you're not confusing Oracle database with Oracle SQL Developer?

The database itself has no date format, the date comes out of the database in raw form. It's up to the client software to render it, and SQL Developer does use YYYY-MM-DD as its default format, which is next to useless, I agree.

edit: As was commented below, SQL Developer can be reconfigured to display DATE values properly, it just has bad defaults.

like image 170
skaffman Avatar answered Sep 19 '22 09:09

skaffman


If you are using this query to generate an input file for your Data Warehouse, then you need to format the data appropriately. Essentially in that case you are converting the date (which does have a time component) to a string. You need to explicitly format your string or change your nls_date_format to set the default. In your query you could simply do:

select to_char(some_date, 'yyyy-mm-dd hh24:mi:ss') my_date   from some_table; 
like image 40
Doug Porter Avatar answered Sep 22 '22 09:09

Doug Porter