How does Oracle DB round milliseconds in its date function?
For example if sysdate is run at exactly “05/25/2012 01:15:25.900”, would the date be stored as “05/25/2012 01:15:26” (rounding up) or as “05/25/2012 01:15:25” (rounding down)?
Does it round up for everything beyond half a millisecond, and down for everything lower than half a millisecond?
Here is a simple test I put together:
SELECT to_char(systimestamp, 'dd-mm-yyyy hh:mi:ss:ff') as sys_time_stamp,
to_char(
TO_DATE (
TO_CHAR (SYSTIMESTAMP, 'YYYY-MON-DD HH24:MI:SS'),
'YYYY-MON-DD HH24:MI:SS'),
'dd-mm-yyy hh:mi:ss') as sys_date
FROM DUAL;
Run 1
sys_time_stamp: 25-05-2012 12:37:32:798000
sys_date: 25-05-012 12:37:32
Run 2
sys_time_stamp: 25-05-2012 12:43:41:322000
sys_date: 25-05-012 12:43:41
This would indicate that at least when converting a systimestamp to a date the milliseconds are just dropped. But when sysdate is actually generated, are milliseconds actually just dropped?
Rounding the fractions of time up would result in the sysdate being on average half a second fast.
It would flip to the next day at 23:59:59.500.
This would obviously be idiotic, so I’m going to go with truncation rather than rounding.