Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > datetime.datetime and mysql different after python2.3

Reply
Thread Tools

datetime.datetime and mysql different after python2.3

 
 
Tobiah
Guest
Posts: n/a
 
      06-01-2011
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
 
Reply With Quote
 
 
 
 
Tobiah
Guest
Posts: n/a
 
      06-01-2011

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


News reader stripped newlines

 
Reply With Quote
 
 
 
 
Thomas Rachel
Guest
Posts: n/a
 
      06-03-2011
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Python and Connecting to MySQL remotely WITHOUT MySQL installedon local computer dave Python 4 11-18-2010 04:19 AM
Re: How to insert PDF file in to MySql and read it from MySql toJAVA App Jeffrey H. Coffield Java 1 07-24-2009 12:29 AM
Re: How to insert PDF file in to MySql and read it from MySql to JAVA App Roedy Green Java 0 07-23-2009 05:30 PM
mySQL Ruby Gem and MAMP mySQL Mark Meijer Ruby 3 02-03-2008 04:19 AM
Has Anyone build A Mysql Module for ruby1.8.2 and Mysql 4.1.8 bin liu Ruby 1 12-22-2004 03:39 AM



Advertisments