Troubleshooting "descriptor 'date' requires a 'datetime.datetime' object but received a 'int'"

It seems that you have imported datetime.datetime module instead of datetime. This should work though:

import datetime
currentdate = raw_input("Please enter todays date in the format dd/mm/yyyy: ")
day,month,year = currentdate.split('/')
today = datetime.date(int(year),int(month),int(day))

..or this:

from datetime import date
currentdate = raw_input("Please enter todays date in the format dd/mm/yyyy: ")
day,month,year = currentdate.split('/')
today = date(int(year),int(month),int(day))

Do you import like this?

from datetime import datetime

Then you must change it to look like this:

import datetime

Explanation: In the first case you are effectively calling datetime.datetime.date(), a method on the object datetime in the module datetime. In the later case you create a new date() object with the constructor datetime.date().

Alternatively, you can change the import to:

from datetime import datetime, date

and then construct with date(y,m,d) (without the datetime. prefix).


if you already have

from datetime import datetime

then you can construct like so:

christmas = datetime(2013,12,25)