Charlie Epps Charlie Epps - 1 year ago 98
Python Question

Parse a string with a date to a datetime object

How can I parse a string like "01-Jan-1995" to a Python


Answer Source

On the whole you'd parse date and time strings with the strptime functions in time or datetime modules. Your example could be parsed with:

import datetime
datetime.datetime.strptime("01-Jan-1995", "%d-%b-%Y")

Note that parsing month names is locale-dependent.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download