the_drow
the_drow

Reputation: 19181

How to convert a string containing the month's name to an integer?

Is there a way to convert a string containing the month's name to an integer that is dependent on the current locale?
I know that somedate.strftime("%B") can convert a date time object to a string containing the month's name according to the current locale but is there way to go backwards?

Upvotes: 3

Views: 365

Answers (1)

Wooble
Wooble

Reputation: 89867

strptime() does the inverse of what strftime() does.

>>> datetime.datetime.strptime("February", "%B").month
2

Upvotes: 6

Related Questions