datetime.datetime and mysql different after python2.3

Tim Roberts timr at probo.com
Wed Jun 1 23:41:36 EDT 2011


Tobiah <toby at rcsreg.com> wrote:
>
>I'm grabbing two fields from a MySQLdb connection.
>One is a date type, and one is a time type.
>
>So I put the values in two variables and print them:
>...
>In python 2.3.4, I get:
>
><type 'DateTime'> <type 'DateTimeDelta'>
>2010-07-06 09:20:45.00
>
>Put in python2.4 and greater, I get this:
>
><type 'datetime.date'> <type 'datetime.timedelta'>
>2010-07-06
>
>So I'm having trouble adding the two to get one
>datetime.

Many of the database layers switched to the built-in "datetime" module when
it was introduced in 2.4.  Prior to that, they had to use custom classes.

  date, time = get_fields()
  date = datetime.datetime.fromordinal( date.toordinal() )
  print str(date+time)
-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-list mailing list