[freetds] bug: converting to smalldatetime

Lowden, James K LowdenJK at bernstein.com
Wed May 12 17:28:23 EDT 2004

If you are using bcp to load dates, you'll want to know about this.  

Using freebcp to load this file:

$ head ivr.dat

into a table whose second column is smalldatetime, I get 

1> select count(*), year(AsOf), min(AsOf), max(AsOf) from ivr group by year(AsOf) order by year(AsOf)
2> go

 ----------- ----------- -------------------- --------------------
         260        1900   Jan 3 1900 12:00AM  Dec 29 1900 12:00AM

If the date string ends in '-99' I get 1999, if '-01' then 2001.  But '-00' is a trip to This Old House.  

The error is in src/tds/convert.c::store_year().  Patch attached.  

store_year(int year, struct tds_time *t)

	if (year <= 0)	// should be < 0
		return 0;

	if (year < 100) {
		if (year > 49)
			t->tm_year = year;
			t->tm_year = 100 + year;
		return (1);


The information contained in this transmission may contain privileged and confidential information 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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: convert.c.diff
Type: application/octet-stream
Size: 441 bytes
Desc: convert.c.diff
Url : http://lists.ibiblio.org/pipermail/freetds/attachments/20040512/6e252741/attachment.obj 

More information about the FreeTDS mailing list