Python MySQL API and date data type
Aaron Bingham
bingham at cenix-bioscience.com
Fri Aug 27 02:58:03 EDT 2004
Yong Wang wrote:
>>Hi:
>> We have a database system. In the database, we have an
>>attribute called date0, which contains date data (format:
>>i. e. 2004-08-12). I wrote a script to fetch the data
>>in a specified time period:
>>for exaplme:
>>date1 = raw_input('start date ')
>>date2 = raw_input('end date ')
>>
>>ie. date1 = '2004-08-12'
>> date2 = '2004-08-20'
>>run = ('SELECT * FROM account WHERE (date0 >= date1) and (date0 <= date2)')
>>data = dbh[runn]
>>.....
>>
>>
You are getting database columns and Python variables confused. I am
not familiar with MySQLdb in particular, so I may have a couple details
wrong, but you probably meant something like this:
data = db.query('SELECT * FROM account WHERE (date0 >= %s) and (date0 <=
%s)', (date1, date2))
This will substitute the *values* of the Python variables date1 and
date2 into the query for you.
Regards,
--
--------------------------------------------------------------------
Aaron Bingham
Application Developer
Cenix BioScience GmbH
--------------------------------------------------------------------
More information about the Python-list
mailing list