datetime.datetime and mysql different after python2.3

T

Tobiah

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:

import datetime
date, time = get_fields() # for example
print str(type(date)), str((type(time)))
print str(date + time)

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.

Thanks for any insight.

Tobiah
 
T

Thomas Rachel

Am 01.06.2011 20:42 schrieb Tobiah:
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:

import datetime
date, time = get_fields() # for example
print str(type(date)), str((type(time)))
print str(date + time)

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.

Here you can do the following:

import datetime
date, time = get_fields() # for example
print str(type(date)), str((type(time)))
dt = datetime.datetime(*date.timetuple()) + time
print dt

(BTW: print calls str() in an case, so it is not needed to put it
explicitly here...)


Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top