How are dates stored in Oracle? For example I know most systems use Epoch time to determine what time it is. By calculating how many seconds away from January 1st 1970. Does Oracle do this as well?
The reason I am asking this is I noticed if you take two dates in Oracle and subtract them you get a floating point of how many days are between.
Example
(Sysdate - dateColumn)
would return something like this (depending on the time)
3.32453703703703703703703703703703703704
Now is Oracle doing the conversion and spitting that format out, or does Oracle store dates with how many days it is away from a certain time frame? (Like Epoch time)
From the manual at http://docs.oracle.com/cd/E11882_01/server.112/e26088/sql_elements001.htm#sthref151
So apparently it's not storing an epoch value which is also confirmed by this chapter of the manual:
The are two types 12 and 13
http://oraclesniplets.tumblr.com/post/1179958393/my-oracle-support-oracle-database-69028-1
Type 13
2012-11-26 16:41:09
Type 12
0012-02-07 00:00:00
The two data types
12
and13
are for two different purposes.SYSDATE
/CURRENT_DATE
, also when converting a string literal into date usingTO_DATE
or ANSI Date literalDATE 'YYYY-MM-DD'
.Test cases:
Basic table setup for type 12:
Check the different cases:
Using ANSI Date literal, just like TO_DATE:
As you can see, while storing a date in the table, it uses type 12. The second type 13 is used when converting a string literal into date using date functions or when date returned by internal date functions like
SYSDATE
/CURRENT_DATE
.