Home > OS >  How to alert if the expire date is close to now date in tkinter
How to alert if the expire date is close to now date in tkinter

Time:02-13

I make like a shop market in tkinter, I tried to make a function that send me a messagebox.showwarning() If (date_now - 5_days) == expire_date

I tried this code in this question before But doesn't works:

from datetime import datetime, date
datet = '15-12-2015'

ExpirationDate = datetime.strptime(datet,"%d-%m-%Y").date()
now = date.today()
if (now - 5) == ExpirationDate:
    messagebox.showwarning("Expired item", "This item is Expired")

CodePudding user response:

You should use the timedelta to define 5 days like:

from datetime import timedelta

five_days = timedelta(days=5)

You should also fix the if statement, testing for exact equality ignores all dates after the expiration. Why not use >=.

  • Related