python datetime module and if statements -
i beginner making small project calculate something. need program use numbers depending on date. want program if manufacturing date between 2 dates. want know how use if statement datetime module? have far:
import datetime manufacturingdate = input('manufacturingdate: ') manufacturingdate = datetime.datetime.strptime(manufacturingdate,"%d/%m/%y") if (manufacturingdate >= datetime.date(1/1/2001) , manufacturingdate <= datetime.date(31/1/2008)): #do
you need 2 boundary dates compare them against input date. can use datetime.strptime
did input date.
then apply if statement see if date in interval:
from datetime import datetime date_format = "%d/%m/%y" manufacturing_date = input('manufacturing date: ') manufacturing_date = datetime.strptime(manufacturing_date,date_format) if (datetime.strptime("1/1/2001", date_format) <= manufacturing_date < datetime.strptime("31/1/2008", date_format)): #do
Comments
Post a Comment