Created
June 26, 2015 15:52
-
-
Save thelahunginjeet/252369938a749671da58 to your computer and use it in GitHub Desktop.
Simple translator between 'mm/dd/yyyy hh:mm:ss' object and python datetime object.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime as dt | |
def date_parser(datestring): | |
""" | |
Accepts a datestring in the format: | |
mm/dd/yyyy hh:mm:ss | |
and returns a python datetime object with all relevant fields properly set. | |
""" | |
mdy = [int(x) for x in datestring.split(' ')[0].split('/')] | |
hms = [int(x) for x in datestring.split(' ')[1].split(':')] | |
return dt.datetime(year=mdy[2],month=mdy[0],day=mdy[1],hour=hms[0],minute=hms[1],second=hms[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment