1👍
from dateutil import parser
date_string = '2016-04-07 23:00:00'
date_object = parser.parse(date_string)
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")
- Getting model instance by variable model name and pk
- Django custom decorator user_passes_test() can it obtain url parameters?
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))
- How can I calculate a date in a Django model?
- Variable in setting file using in template
- Heroku can't find pip when I push app to it
Source:stackexchange.com