[Tutor] date conversion
Kent Johnson
kent37 at tds.net
Wed Apr 5 19:50:06 CEST 2006
Python wrote:
> On Wed, 2006-04-05 at 10:50 -0400, Kent Johnson wrote:
>> Ray Allen wrote:
>>> I would like Python to convert a date returned by MySQL (2006-04-05)
>
> Kent's advice below is of course correct, but I'd bet your variable is
> already a datetime.date (or mx.DateTime.Date with older Python
> releases). In that case you'd already be at step 7.
>
> When executing your update statement use the args field.
>
> cursor.execute("UPDATE table SET mydate=%s WHERE id=%s", (date_variable, recordID))
>
>
> You should not have to worry about getting your date into the proper
> string format for the database SQL syntax.
Good point. You may well be getting some kind of date object back from
MySQL, too, rather than a string.
Kent
More information about the Tutor
mailing list