Skip to Content.
Sympa Menu

freetds - Re: [freetds] Dates fetched from MSSQL are off by 1 month

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Lowden, James K" <james.k.lowden AT alliancebernstein.com>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] Dates fetched from MSSQL are off by 1 month
  • Date: Thu, 16 Nov 2006 12:00:15 -0500

> From: Ole Christian Schroder
> Sent: Thursday, November 16, 2006 10:43 AM
>
> More specifically the
> month is adjusted by one, thus november becomes october (or more
> correctly, 11 becomes october).
>
> The date is entered and fetched from the database with the same
> application. It appears that the date is correctly stored in the
> db, but adjusted when it is read, thus the application sees the
> wrong date.

Exactly: "the date is correctly stored in the db, but adjusted when it is
read". It is *not* adjusted by FreeTDS. FreeTDS passes the data from the
server to the client. Verbatim. That's its job. Anything else[1] a bug.

You can verify you're getting the same information with both versions of
FreeTDS using, say, tsql on both machines.

The only function I can think of that yields the month as a number in db-lib
(the library used by the PHP mssql extension) is dbdatecrack(). FreeTDS
adheres to Sybase's definition of this function; there is no conditional code
based on --enable-msdblib. That's arguably a bug, because Microsoft and
Sybase define the range of DBDATEREC::month differently. Sybase uses [0-11],
Microsoft [1-12].

> <--
> ...under linux the driver for mssql is SYBASE alias, and FreeTDS is set
> to work with SYBASE by default. The problem is that sybase counts
> months from 0 to 11, and mssql from 1 to 12. that´s the cause of
> that strange one month less. To correct this, u have to compile
> FreeTDS with a "--enable-msdblib". -->

That might do the trick. It may be that PHP has conditional code, and that
unless you define --enable-msdblib, it assumes you're using a Sybase server,
meaning that when it calls dbdatecrack() and sees DBDATEREC::month of 11, it
thinks that means "December".

That hypothesis fits the facts in the opposite direction AIUI. But it's
worth trying. Let us know.

> On RHE4 we are using freetds-0.63-1.2.el4.rf and on the RH9 we are
> using freetds-0.62-9

BTW we released 0.64 some six months ago. As long as you're upgrading, you
might want to see if you can get that version.

--jkl
[1] apart from character set conversion, of course.

-----------------------------------------
The information contained in this transmission may be privileged and
confidential and is intended only for the use of the person(s) named
above. If you are not the intended recipient, or an employee or agent
responsible
for delivering this message to the intended recipient, any review,
dissemination,
distribution or duplication of this communication is strictly prohibited. If
you are
not the intended recipient, please contact the sender immediately by reply
e-mail
and destroy all copies of the original message. Please note that we do not
accept
account orders and/or instructions by e-mail, and therefore will not be
responsible
for carrying out such orders and/or instructions. If you, as the intended
recipient
of this message, the purpose of which is to inform and update our clients,
prospects
and consultants of developments relating to our services and products, would
not
like to receive further e-mail correspondence from the sender, please "reply"
to the
sender indicating your wishes. In the U.S.: 1345 Avenue of the Americas, New
York,
NY 10105.




Archive powered by MHonArc 2.6.24.

Top of Page