I'm looking to understand why module and class "datetime" can't work together. In the code below i have 3 choices :
- Else date.today doesn't work
- Else strptime doesn't work
- Else they can't work together :"TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'datetime.date'
import datetime
film_name = input("What is the movie name ?")
Date = input("When it's up ?")
date_format = "%d/%m/%y"
d1 = datetime.datetime.strptime(Date, date_format)
d0 = datetime.date.today()
print(d0,d1)
delta = d1 - d0
print("Il reste {} dodos avant la sortie de {}".format(delta, film_name))
I tried a lot of things like creating some function, then a class and nothing work. If someone can explain to me why or give me another method to do it ?
Thanks for your help and sorry for my english, not my native language. If you have any question i'm here
#Edit : as suggested below, i tried : ''' import "from datetime import date" d0 = datetime.combine(date.today(), datetime.min.time()) '''
The answer is : AttributeError: module 'datetime' has no attribute 'combine'
#Edit_2 : If i use : ''' d0 = datetime.datetime.combine(datetime.date.today(), datetime.datetime.min.time()) ''' It almost works, i got :
Il reste 304 days, 0:00:00 dodos avant la sortie de Avatar
But i still see the time ?
#Edit3
If you need advice about it, please check the comments. Then the right answer is :
import datetime
film_name = input("What is the movie name ?")
Date = input("When it's up ?")
date_format = "%d/%m/%y"
d1 = datetime.datetime.strptime(Date, date_format)
d0 = datetime.datetime.combine(datetime.date.today(), datetime.datetime.min.time())
d2 = (d1 - d0).days
print("Il reste {} dodos avant la sortie de {}".format(d2, film_name))