[Fixed]-Django: Convert string to datetime object

1👍

from dateutil import parser



date_string = '2016-04-07 23:00:00'
date_object = parser.parse(date_string)
👤Phares

0👍

change

from datetime import datetime

to

import datetime

and try this. hope this helps..

import datetime
datetime.datetime.strptime(dt, "%Y-%m-%d %H:%M:%S")

0👍

Try this code, I think this is a good way to convert specific string to datetime:

import datetime 

dt = '2016-04-07 23:00:00'
date_time_object = datetime.datetime.strptime(dt, "%Y-%m-%d %H:%M:%S")
print((date_time_object))
print(type(date_time_object))

Leave a comment