php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: akukula at navopgd dot pl
New email:
PHP Version: OS:

 

 [2005-02-18 16:03 UTC] akukula at navopgd dot pl
Description:
------------
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 1.86.2.41

According to description found in:

<http://manuals.sybase.com/onlinebooks/group-cnarc/cng1110e/dblib/@Generic__BookTextView/15105;pt=39614>

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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-18 16:20 UTC] fmk@php.net
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: <http://lists.ibiblio.org/pipermail/freetds/2002q3/008336.html>
 [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: Sat Dec 21 18:01:29 2024 UTC