View Single Post
Old 2005-01-21, 10:03   #1
leifbk's Avatar
May 2004
Oslo, Norway

23·3·5 Posts
Default Date conversion with Python

I'm dabbling with a small MySQL database that stores my finished exponents. A Python script gets the cleared exponent from the Individual report, and then does some munging to get the data into a MySQL insert command. I won't post the entire code here at the moment, but if anyone is interested, I just might do it in a while

Now, to convert the date from GIMPS format ("21-Jan-05 10:43") to MySQL format ("2005-01-21 10:43:00") I found that Python has excellent built-in functionality to do so. The documentation is found online at

from time import strptime, strftime

def convertDate(mystring): 
    mytimeobj = strptime(mystring, "%d-%b-%y %H:%M")
    return strftime("%Y-%m-%d %H:%M:00", mytimeobj)
I hope this might be of use to someone

regards, Leif.
leifbk is offline   Reply With Quote