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.
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.
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.
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.
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.
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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With