0

Here is the datetime string: dt = '2016-04-07 23:00:00'

I have tried datetime.strptime(year+"-"+day+"-"+month+" "+hour+":"+mins+":"+"00", '%Y-%d-%m %H:%M:%S') but I get this error:

type object 'datetime.datetime' has no attribute 'datetime'

Helpme
  • 505
  • 3
  • 7
  • 18
  • You should try to create a [mcve] – Sayse Jun 01 '16 at 10:36
  • Possible duplicate of [Converting string to datetime object in python](http://stackoverflow.com/questions/2609259/converting-string-to-datetime-object-in-python) – trinchet Jun 01 '16 at 11:20

3 Answers3

1
from dateutil import parser



date_string = '2016-04-07 23:00:00'
date_object = parser.parse(date_string)
Phares
  • 1,008
  • 13
  • 20
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")
SuperNova
  • 25,512
  • 7
  • 93
  • 64
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))
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
MD. SHIFULLAH
  • 913
  • 10
  • 16