Buğra İşgüzar
Buğra İşgüzar

Reputation: 111

string to datetime.datetime type format

I'm getting date input from user. It's coming to me as string object and I can't do any operation on it.

I couldn't change my string to datetime object with datetime library.

24th of May 2016        04:00

How can I convert this string to a datetime type?

Upvotes: 1

Views: 93

Answers (1)

wim
wim

Reputation: 363616

Try python-dateutil, it will chew that string up no problems:

>>> from dateutil.parser import parse
>>> parse('24th of May 2016        04:00')
datetime.datetime(2016, 5, 24, 4, 0)

Upvotes: 2

Related Questions