Python forum for Python programmers

Datetime.datetime and mysql different after python2.3

Jun 1, 2011 6:42 pm
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

Jun 1, 2011 6:47 pm
Tobiah
Re: datetime.datetime and mysql different after python2.3


> import datetime
> 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 Roberts
Re: datetime.datetime and mysql different after python2.3

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.


Previous Thread: Feedparser hanging after I/O error
Next Thread: Comparison operators in Python

Related Forum Topics
Maybe useful : datetime conversion
This is a multi-part message in MIME format.
--------------010304010205020303040102
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

hello,

using datetimes from a lot of different sources,
in many languages,
I had about 30 python helper routines,
which I...
Sub-classing datetime
I'm just making the transition from 2 to 3 for one module.

With Python 2.7, I had the benefit of mx datetime, but this is not yet
available for Python 3.2.

I find that the 3.2 datetime is not subclassable, for reasons that were
known some years back.

It would help if there was a note...
Datetime module and timezone
In the datetime module, it has support for a notion of timezone but is
it possible to use one of the available timezone (I am on Linux). Linux
has a notion of timezone (in my distribution, they are stored
in /usr/share/zoneinfo). I would like to be able 1) to know the current
timezone and 2)...
PyWarts: time, datetime, and calendar modules
The interface for these modules is not intuitive. Instead of creating
true OOP objects we have lists and strings. Any calendar object should
expose string names of both: days of the week and months of the year.
It seems one (or possibly more) of the three expose this important
info however i...
Python, django datetime to string conversation helper
Online tool allows to select datetime to string format directives
quickly and to check result.


Obnoxious postings from Google Groups (was: datetime issue)
Νικόλαος Κούρας <nikos.gr33k@gmail.com> writes:

> Iam sorry i didnt do that on purpose and i dont know how this is done.
>
> Iam positng via google groups using chrome, thats all i know.

It is becoming quite clear that some change has happened recently to
Google Groups that...
Fromutc: dt.tzinfo is not self: pytz.timezone('UTC').fromutc(datetime.utcnow())
hi

>>> import pytz
>>> from datetime import datetime
>>> pytz.timezone('GMT0').fromutc(datetime.utcnow())
datetime.datetime(2011, 10, 19, 7, 54, 45, 579125,
tzinfo=<StaticTzInfo 'GMT0'>)
>>> pytz.timezone('UTC').fromutc(datetime.utcnow())
Traceback (most recent call last):
File...
MySQL: AttributeError: cursor
Hi All,
I'm using Python 2.7 and having a problem creating the cursor below.
Any suggestions would be appreciated!

import sys
import _mysql

print "cursor test"

db =
_mysql.connect(host="localhost",user="root",passwd="mypw",db="python-
test")

cursor = db.cursor()

>>>
cursor...
Will MySQL ever be supported for Python 3.x?
The MySQLdb entry on SourceForge
(http://sourceforge.net/projects/mysql-python/)
web site still says the last supported version of Python is 2.6.
PyPi says the last supported version is Python 2.5. The
last download is from 2007.

I realize there are unsupported fourth-party...
SQLAlchemy: How to do Table Reflection and MySQL?
Hi, I'm fairly new to Python, and I'm trying to figure out how to use
SQLAlchemy to connect to a MySQL DB and use table reflection to set up
SQLAlchemy's tables. But the SQLAlchemy documentation is gigantic and
frankly kinda making my head spin, so I'm having trouble even finding
any...