Converting human readable date into integer values

Posted by kahrn on Stack Overflow See other posts from Stack Overflow or by kahrn
Published on 2010-05-27T12:06:35Z Indexed on 2010/05/27 12:11 UTC
Read the original article Hit count: 203

Filed under:
|
|

Hello all,

I am looking to do something really simple. Merely convert a string, such as 'december' into something I can use with MySQL (such as '12').

At the moment I use a dict,

month_map = {
    'december': '12',
    'november': '11',
    'october': '10',
    'september': '09',
    'august': '08',
    'july': '07',
    'june': '06',
    'may': '05',
    'april': '04',
    'march': '03',
    'february': '02',
    'january': '01'
}

and then month_map.get('december').

Does any function already exist within the standard python modules that can achieve this? Apologies if this has already been asked.. the questions I have found using search seem a little different.

© Stack Overflow or respective owner

Related posts about python

Related posts about mysql