FIX: Error Message "Invalid Time Format" When You Insert Date/Time With Maximum Values (259691)
The information in this article applies to:
- Microsoft Data Access Components 2.1 (GA)
- Microsoft Data Access Components 2.1 SP1
- Microsoft Data Access Components 2.1 SP2
- Microsoft Data Access Components 2.5
- Microsoft ODBC Driver for SQL Server 3.7
This article was previously published under Q259691 SYMPTOMS
When you use the Microsoft SQL Server ODBC driver and you use SQLSetPos to insert or update date or time values that contain the maximum allowable values for the hour, minute, second and millisecond portions (such as 1999-10-03 23:59:59:999), the insert statement succeeds but incorrect values are saved to the database.
If you attempt to reselect the date/time values back, the statement either generates an error or returns incorrect values, depending on how the date/time field is bound. If the field is bound as a SQL_C_TIMESTAMP, the error message that follows occurs:
SQLState = 22007
[Microsoft][ODBC SQL Server ODBC Driver]Invalid time format
When the field is bound as a SQL_C_CHAR, no error occurs; however, incorrect values are returned, such as 1999-10-03 24:00:00.000. This can generate errors in the receiving application because 24:00:00.000 is not a valid date/time value.
This error occurs with the Windows 2000/MDAC 2.5 build of the SQL Server ODBC driver (version 3.70.820) and earlier.
CAUSE
An error in the algorithm that converts the date/time is not rolling the hours portion of the time over to the days portion of the date.
RESOLUTIONA supported hotfix is now available from Microsoft, but it is only intended to correct the problem that is described in this article. Only apply it to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next Microsoft Data Access Components service pack that contains this hotfix. To resolve this problem immediately, contact Microsoft Product Support Services to obtain the fix. For a complete list of Microsoft Product Support Services phone numbers and information about support costs, visit the following Microsoft Web site: NOTE: In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The typical support costs will apply to additional support questions and issues that do not qualify for the specific update in question.
The English version of this fix should have the following file attributes or later:
Date Version Size File name
-----------------------------------------------------
04/04/00 3.70.0784 24,848 bytes Odbcbcp.dll
04/04/00 3.70.0784 516,368 bytes Sqlsrv32.dll
Workaround
Here are two potential workarounds for this problem:
- If possible, perform the inserts and updates through direct SQL statements, which then lets SQL Server handle the conversion of the date/time values.
-or-
-
If storage of milliseconds is not necessary, define the field as a smalldatetime datatype instead of datetime. The smalldatetime datatype only uses 4 bytes for storage, and does not include millisecond precision.
STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
Modification Type: | Minor | Last Reviewed: | 10/12/2005 |
---|
Keywords: | kbHotfixServer kbQFE kbbug kbCodeSnippet kbDatabase kbfix kbMDAC210SP2fix kbQFE KB259691 |
---|
|