Skip to content

Instantly share code, notes, and snippets.

@kisom
Created March 7, 2011 17:09
Show Gist options
  • Save kisom/858808 to your computer and use it in GitHub Desktop.
Save kisom/858808 to your computer and use it in GitHub Desktop.
get datetime.datetime object from str(datetime.datetime)
def get_datetime(timestamp):
"""
Returns a datetime object from str(datetime.datetime).
"""
ctor = []
timestamp = timestamp.split()
date = [ int(i) for i in timestamp[0].split('-') ]
time = [ int(i) for i in timestamp[1].replace('.', ':').split(':') ]
ctor.extend(date)
ctor.extend(time)
return eval('datetime.datetime(%d, %d, %d, %d, %d, %d, %d)' % tuple(ctor))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment