In my code I ask the user for a date in the format dd/mm/yyyy
.
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))
This returns the error
TypeError: descriptor 'date' requires a 'datetime.datetime' object but received a 'int'
if I remove the int()
then I end up with the same error only it says it received a 'str'
What am I doing wrong?
The strftime() method returns a string representing date and time using date, time or datetime object.
To create a time object, we use the time class in the datetime module using the statement, datetime. time(hour, minutes, seconds), where hour is the hour, minutes is the minutes, and seconds is the seconds.
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With