Converting DD MM YYYY into YYYY-MM-DD?

Che M cmpython at gmail.com
Mon Aug 17 19:58:28 EDT 2009


On Aug 17, 6:26 pm, Gilles Ganault <nos... at nospam.com> wrote:
> Hello,
>
>         I need to convert DD MM YYYY dates into the MySQL-friendly
> YYYY-MM-DD, and translate the month name from literal French to its
> numeric equivalent (eg. "Janvier" into "01").
>
> Here's an example:
>
> SELECT dateinscription, dateconnexion FROM membres LIMIT 1;
> 26 Mai 2007|17 Août 2009 - 09h20
>
> I'd like to update the row into "2007-05-26" and "2009-08-17 09:20",
> respectively.
>
> What is the best way to do this in Python?
>
> Thank you.

Likely this is not the best way, but I would do, for
the first one (and the same idea for the second):

def convert(date):
    frenchdict = {'Mai':'May'} #etc...
    day = mystring[:2]
    month = frenchdict[ mystring[3:6] ]
    year = mystring[7:11]
    newdate = year+'-'+month+'-'+day
    print 'newdate is ', newdate




More information about the Python-list mailing list