0

How do I check a body text for different date formats and convert it into datetime format? The body of text could be:
May 6 2014 (can use parser here)
Tue May 6 2014
mm/dd/yyyy , yyyy/mm/dd etc
yyyy:dd::mm, mm:dd:yyyy
and so on.
Is there an easy way to check what format the date is in ?

sbalajis
  • 1,939
  • 3
  • 14
  • 14
  • related: [Converting string into datetime](http://stackoverflow.com/q/466345/4279) – jfs May 07 '14 at 21:43
  • related: [Python date string to date object](http://stackoverflow.com/q/2803852/4279) – jfs May 07 '14 at 21:44

1 Answers1

1

python-dateutil module is pretty good at parsing datetime strings in different formats:

>>> from dateutil import parser
>>> parser.parse('May 6 2014')
datetime.datetime(2014, 5, 6, 0, 0)
>>> parser.parse('Tue May 6 2014')
datetime.datetime(2014, 5, 6, 0, 0)

Also see:

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195