The format of the timestamp data is the same as the date data. Note that the TO_CHAR function supports date and timestamp, but Trunc does not support timestamp data types. This has made it clear that using the timestamp data type is more accurate than the date data type when the difference between two times is extremely important.
If you want to display timestamp decimal seconds information, refer to the following:
1 Select To_char (time1, ' mm/dd/yyyy HH24:MI:SS:FF3 ') "Date" from date_table
Date
-----------------------
06/20/2003 16:55:14:000
06/26/2003 11:16:36:000
In the example above, I'm only realistic about 3 bits after the decimal point.
It is easier to calculate the data differences between timestamp than the old date data type. When you subtract directly, see what happens. The results will be easier to understand, the first line of 17 days, 18 hours, 27 minutes and 43 seconds.
1 SELECT time1,
2 Time2,
3 substr ((time2-time1), InStr ((time2-time1), "+7,2") seconds,
4 substr ((time2-time1), InStr ((time2-time1), "+4,2") minutes,
5 substr ((time2-time1), InStr ((time2-time1), "+1,2") hours,
6 trunc (To_number (substr (time2-time1), 1,instr (Time2-time1, ')))
7 trunc (To_number (substr (time2-time1), 1,instr (Time2-time1, '))/7) weeks
8* from Date_table
TIME1 TIME2 SECONDS MINUTES HOURS days WEEKS
------------------------- -------------------------- ------- ------- ----- ---- -----
06/20/2003:16:55:14:000000 07/08/2003:11:22:57:000000 43 27 18 17 2
06/26/2003:11:16:36:000000 07/08/2003:11:22:57:000000 21 06 00 12 1
This means no longer needing to care about how many seconds a day is in trouble calculations. Therefore, getting the number of days, months, days, hours, minutes and seconds becomes a matter of extracting numbers with the SUBSTR function.