|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32022 Wrong implementation of mssql.datetimeconvert=Off
Submitted: 2005-02-18 16:03 UTC Modified: 2005-02-19 02:50 UTC
From: akukula at navopgd dot pl Assigned:
Status: Not a bug Package: MSSQL related
PHP Version: 4.3.8 OS: Mandrake Linux 10.1
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: akukula at navopgd dot pl
New email:
PHP Version: OS:


 [2005-02-18 16:03 UTC] akukula at navopgd dot pl
Turning off mssql.datetimeconvert causes dates returned from SQL queries to be shifted one month back.

The bug is in line 892 of php_mssql.c,v

According to description found in:


dbdatecrack() returns month in range 0...11. So in sprintf() the argument dateinfo.month should become dateinfo.month+1

Reproduce code:
mssql_query("SELECT CONVERT(DATETIME, '2005-01-01')");
$a = mssql_fetch_row($res); echo $a[0] . "\n";
mssql_query("SELECT CONVERT(DATETIME, '2005-12-01')");
$a = mssql_fetch_row($res); echo $a[0] . "\n";

Expected result:
2005-01-01 00:00:00
2005-12-01 00:00:00

Actual result:
2005-00-01 00:00:00
2005-11-01 00:00:00


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-18 16:20 UTC]
FreeTDS should be compiled using --enable-msdblib if you are compiling php with --with-mssql.
 [2005-02-18 16:39 UTC] akukula at navopgd dot pl
This is not bogus and I ask you to apply this simple fix. This sprintf() violates dbdatecrack() specification. sprintf() prints invalid date and recompilation of external library is not a fix.
 [2005-02-19 01:49 UTC] akukula at navopgd dot pl
Okay this one is bogus. There are conflicting prototypes for dbdatecrack(3) in Sybase and SQL Server. Sybase requires month to be an offset 0-11 and SQL Server says it should be a proper month 1-12.

So if you use SQL Server and not Sybase, be sure to compile FreeTDS with --enable-msdblib, as suggested by PHP documentation, to get proper dates in PHP.

If you need more details, see this: <>
 [2005-02-19 02:50 UTC] akukula at navopgd dot pl
Mandrake have not used --enable-msdblib in their RPM.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 21 13:01:27 2024 UTC