-3

how do i write a code that notifies me that a certificate is valid from 17 March 2017 to 16 March 2022 and should be renewed from 17 March 2022 for another validity period of 5 years. Please note that the standard validity period is usually 5 years.

I put together some code on jupyter notebook using python which I ran and got an output as shown in the attached image, I however feel I however know it has not been done right.

find my codes below:

code sample used

Elyon
  • 1
  • 1
  • May be this will help you : https://stackoverflow.com/questions/10048249/how-do-i-determine-if-current-time-is-within-a-specified-range-using-pythons-da – codeholic24 Sep 14 '22 at 11:58

2 Answers2

2

Note that you should post your code as code sample and not as a picture so people have more time to solve your problem than reconstructing your problem.

A solution could be datetime and relativedelta.

import datetime
from dateutil.relativedelta import relativedelta
def time_in_range(start, end, current):

    if start <= current <= end:
        print("Ticket valid")
    else:
        print("Ticket invalid")


start = datetime.date(2015, 1, 30)
end = start + relativedelta(years=5)
current = datetime.datetime.now().date()

This way you can check if a date is in a given range.

Broxy
  • 90
  • 7
  • Thank you very much Broxy. Your response, input and suggestion to append my code as a sample rather than an image is very well received. I will definitely keep that in mind. I joined stack flow today. Still familiarizing myself with it. Thanks again. – Elyon Sep 14 '22 at 11:48
0

Use datetime function of python. Read this Document for details.