Jun 1, 2011 6:42 pm
TobiahI'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
Jun 1, 2011 6:47 pm
Tobiah> import datetime
> date, time = get_fields() # for example
> print str(type(date)), str((type(time)))
> print str(date + time)
> date, time = get_fields() # for example
> print str(type(date)), str((type(time)))
> print str(date + time)
News reader stripped newlines
Jun 2, 2011 3:41 am
Tim RobertsTobiah <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.
>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.
Providenza & Boekelheide, Inc.
Previous Thread: Feedparser hanging after I/O error
Next Thread: Comparison operators in Python
Related Forum Topics
- Maybe useful : datetime conversion
- Sub-classing datetime
- Datetime module and timezone
- PyWarts: time, datetime, and calendar modules
- Python, django datetime to string conversation helper
- Obnoxious postings from Google Groups (was: datetime issue)
- Fromutc: dt.tzinfo is not self: pytz.timezone('UTC').fromutc(datetime.utcnow())
- MySQL: AttributeError: cursor
- Will MySQL ever be supported for Python 3.x?
- SQLAlchemy: How to do Table Reflection and MySQL?