How to make Expiry date calculator using Python and pendulum

PHOTO EMBED

Sun Nov 24 2024 16:34:15 GMT+0000 (Coordinated Universal Time)

Saved by @freepythoncode ##python #coding #python #pendulum

import pendulum

def calc_expire_date(prodact_date, expiry):
    prodact_date = pendulum.parse('{:0>2}-{:0>2}-{:0>2}'.format(*prodact_date))
    target_date = pendulum.duration(**expiry) + prodact_date
    days_to_expire = (target_date.date() - pendulum.now().date()).days
    print(f'Product vaild until : {target_date} You have {days_to_expire} days')


calc_expire_date((2024, 11, 15), expiry = {'days': 15})
content_copyCOPY