Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #6815 > unrolled thread
| Started by | Tobiah <toby@rcsreg.com> |
|---|---|
| First post | 2011-06-01 18:42 +0000 |
| Last post | 2011-06-03 11:05 +0200 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.python
datetime.datetime and mysql different after python2.3 Tobiah <toby@rcsreg.com> - 2011-06-01 18:42 +0000
Re: datetime.datetime and mysql different after python2.3 Tobiah <toby@rcsreg.com> - 2011-06-01 18:47 +0000
Re: datetime.datetime and mysql different after python2.3 Tim Roberts <timr@probo.com> - 2011-06-01 20:41 -0700
Re: datetime.datetime and mysql different after python2.3 Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-06-03 11:05 +0200
| From | Tobiah <toby@rcsreg.com> |
|---|---|
| Date | 2011-06-01 18:42 +0000 |
| Subject | datetime.datetime and mysql different after python2.3 |
| Message-ID | <is616g$h3o$1@speranza.aioe.org> |
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
[toc] | [next] | [standalone]
| From | Tobiah <toby@rcsreg.com> |
|---|---|
| Date | 2011-06-01 18:47 +0000 |
| Message-ID | <is61fv$h3o$2@speranza.aioe.org> |
| In reply to | #6815 |
> import datetime > date, time = get_fields() # for example > print str(type(date)), str((type(time))) > print str(date + time) News reader stripped newlines
[toc] | [prev] | [next] | [standalone]
| From | Tim Roberts <timr@probo.com> |
|---|---|
| Date | 2011-06-01 20:41 -0700 |
| Message-ID | <ea1eu6pfg7ksu890o10a2ruee97hjjbdvu@4ax.com> |
| In reply to | #6815 |
Tobiah <toby@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@probo.com Providenza & Boekelheide, Inc.
[toc] | [prev] | [next] | [standalone]
| From | Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> |
|---|---|
| Date | 2011-06-03 11:05 +0200 |
| Message-ID | <isa85t$7qj$1@r03.glglgl.eu> |
| In reply to | #6815 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web