#311 executing a datetime column update with year < 1900 fails

MySQLdb-1.2
closed
Andy Dustman
MySQLdb (285)
5
2012-09-19
2011-05-02
Jen Andre
No

The MySQL datetime field supports any date > year 1000, but the use of strftime prevents you from passing a python datetime object to cursor.execute() that has a year < 1900.

File "C:\Python26\lib\site-packages\MySQLdb\cursors.py", line 151, in execute
query = query % db.literal(args)

File "C:\Python26\lib\site-packages\MySQLdb\connections.py", line 247, in lite
ral
return self.escape(o, self.encoders)
File "C:\Python26\lib\site-packages\MySQLdb\times.py", line 85, in DateTime2li
teral
return string_literal(format_TIMESTAMP(d),c)
File "C:\Python26\lib\site-packages\MySQLdb\times.py", line 40, in format_TIME
STAMP
return d.strftime("%Y-%m-%d %H:%M:%S")
ValueError: year=1601 is before 1900; the datetime strftime() methods require ye
ar >= 1900

c:\iocg\src\coordinator>

Discussion

  • Jen Andre
    Jen Andre
    2011-05-02

    woops, forgot to mention, I"m using windows 7 with python 2.6. it may be a platform specific issue with strftime().

     
  • wyuenho
    wyuenho
    2011-05-25

    I've hit this bug too. It's really not acceptable since the python API docs clearly says strftime() cannot be used to format year < 1900 and there's an alternative .isoformat() method you can use. This bug currently exists on all platforms and IMHO it's quite serious. Can you quickly patch this up and release a bugfix? Thanks.

     
  • Andy Dustman
    Andy Dustman
    2012-09-07

    Fixed in 659