PRB: Converting Datetime to Another Datatype May Result in Inaccurate Value (281676)
The information in this article applies to:
- Microsoft SQL Server 2000 (all editions)
- Microsoft SQL Server 7.0
This article was previously published under Q281676 SYMPTOMS
When a datetime value is converted into another data type and then converted back into datetime, the datetime value returned may lose its accuracy due to the rounding during the conversion. The new value depends on the precision of the data type to which it was converted.
CAUSE
Values with the datetime data type are stored internally by SQL Server as two 4-byte integers. The first 4 bytes store the number of days before or after the base date, January 1, 1900. The other 4 bytes store the time of day represented as the number of milliseconds after midnight. Accurate conversion will occur only if the data type can store the precise time value.
WORKAROUND
There is no way to completely avoid loss of precision of the milliseconds due to the fact that the rounding must meet the ODBC specification. However, a numeric or decimal data type may have less loss of precision than other types.
Modification Type: | Major | Last Reviewed: | 10/16/2003 |
---|
Keywords: | kbprb KB281676 |
---|
|