Skip to content Skip to sidebar Skip to footer

Use Variable In Re.sub, For Python Parsing Multiple Datetime-format Strings?

I'm trying to come up with a function to translate various human date/time-format strings to Python compatible ones (from '*yyyy-MMM-dd*' to '*%Y-%b-%d*'). So far I built the trans

Solution 1:

Why roll your own when you can use dateutil.parser?

importdateutiloutdate= dateutil.parser.parse(instr, yearfirst=True) 

Solution 2:

Why don't you use strptime:

>>>from datetime import datetime>>>datetime.strptime('2012-12-12', '%Y-%j-%d')
datetime.datetime(2012, 1, 12, 0, 0)

Post a Comment for "Use Variable In Re.sub, For Python Parsing Multiple Datetime-format Strings?"