Question
Hi, I'm working on a Python script that will take in two dates in a function, calculate the number of days between them and display
Hi,
I'm working on a Python script that will take in two dates in a function, calculate the number of days between them and display the output as an integer. Currently, the script is returning a none value. This is the main function.
def dbda(start_date, end_date):
"""Takes two valid date string in "DD-MM-YYYY" format and returns a positive or a negative integer"""
num_days = 0
if len(start_date) == 10 and len(end_date) == 10:
day1,mon1,year1 = start_date.split('-')
d1 = int(day1)
m1 = int(mon1)
y1 = int(year1)
day2,mon2,year2 = end_date.split('-')
d2 = int(day2)
m2 = int(mon2)
y2 = int(year2)
days = y1 - y2
if len(sys.argv) == 3:
if int(days) > 0:
m1,m2 = m2,m1
y1,y2 = y2,y1
d1,d2 = d2,d1
for x in range(int(days)):
y = after(start_date)
num_days+=1
return(num_days)
if int(days) < 0:
for x in range(int(days)):
y = before(start_date)
num_days-=1
return(num_days)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started