Reputation: 153
I am doing a program in pyhon(3.10.1) in which i need to compare an input, in this case the number of a month (for example 05 for may) with the local current time.
from datetime import datetime
month=int(input("insert the number of a month: "))
dt_obj = datetime.now()
dt_frt = dt_obj.strftime("%m")
print(dt_frt)
if (month==dt_frt):
print("the month you selected is equal to the current month")
Then it stops at printing the current month, but does not do what the two last lines say, and it does not give any error. can anybody help me? Thanks.
Upvotes: 0
Views: 22
Reputation: 505
I think you're comparing int
with str
, that's why the if condition isn't true. To fix this, you can remove the int(input(...))
or add a str(...)
around your dt_frt
You can also get the month with just date.month
(doc)
Upvotes: 1