Search code examples
pythondatetimetimestrptime

Unable to convert or understand dates in strange format


I am converting a bunch of dates in a database into unixtimestamp in python. There are entries in the database written like:

Thu Jun 16 10%3A08%3
Wed Jun 8 09%3A39%3A

Can any one tell me what this means? And possibly how to convert this over into a unixtimestamp?

Any other dates such as: Thu Oct 14 15:11:47 I just use strptime to convert it over, but the ones above are giving me issue.

Thanks!


Solution

  • The '%3A' bits are the url encoded representation of a colon :. You can use the urllib.unquote() function to decode those strings:

    >>> urllib.unquote("Wed Jun 8 09%3A39%3A")
    'Wed Jun 8 09:39:' 
    

    ...but it looks like the dates got stored in a fixed-length field and the seconds have been truncated.