mymysql icon indicating copy to clipboard operation
mymysql copied to clipboard

Query and Prepared statements return different dates for same query

Open rmulley opened this issue 11 years ago • 1 comments

This seems to only happen when there is an invalid date in the database. For example, I had the date '1997-00-00' in our database in a field of type date, and I got the following.

dbh.Query(query, id) returned '1997-00-00'

Creating a prepared statement, binding parameters, and executing returned '1996-11-30'.

rmulley avatar Sep 24 '13 19:09 rmulley

Can you provide example code for this issue. Return '1996-11-30' is expected behavior if you obtain date as time.Time type . time.Time stores date as some number and can't represent invalid dates (see http://play.golang.org/p/2Us5Kb4KfQ). The original date can be returned only when server returned date as text and conversion to time.Time wasn't performed. godrv always do this conversion, so you probably use mymysql native interface and use row[i] instead row.Localtime(i).

ziutek avatar Sep 27 '13 13:09 ziutek