-3

I want to return datetime.datetime.strptime(date_visit,"%Y-%m-%d") into my function read_file but python keeps saying that datetime.datetime has no attribute datetime? In the function where I return it´s working. Pls help anyone.

return datetime.datetime.strptime(date_visit,"%Y-%m-%d") 




def read_file(date): 

  all_animals = list() 

  day = datetime.datetime.strptime(date_visit,"%Y-%m-%d").isoweekday()


  datetime.datetime.strptime(date_visit,"%Y-%m-%d") 


  workingday = [1,2,3,4,5]
  • 1
    similar post http://stackoverflow.com/questions/12906402/type-object-datetime-datetime-has-no-attribute-datetime – Hussain Dec 08 '16 at 08:53
  • Possible duplicate of [type object 'datetime.datetime' has no attribute 'datetime'](https://stackoverflow.com/questions/12906402/type-object-datetime-datetime-has-no-attribute-datetime) – John Lyon Mar 07 '18 at 00:17

2 Answers2

1

Just replace import datetime.datetime by import datetime

khelili miliana
  • 3,730
  • 2
  • 15
  • 28
0

Of course datetime.datetime does not have the attribute datetime. You should use it like this:

from datetime import datetime

datetime.strptime(...)

Or:

import datetime

datetime.datetime.strptime(...)

To use datetime.datetime.strptime() you need to import the whole module:

import datetime

The second datetime is a type in the first one, and it has strptime() function. For more details please check this link:

datetime — Basic date and time types

ettanany
  • 19,038
  • 9
  • 47
  • 63