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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!