0

I want to get days between two dates.

I got a code, but this is little bit different.

Here is my code.

End date is fixed by 2021/5/4.

yearStart = int(input())
monthStart = int(input())
dayStart = int(input())

yearEnd = 2021
monthEnd = 5
dayEnd = 4

months = [31,28,31,30,31,30,31,31,30,31,30,31]

def isLeapYear(year):
    return (year%4==0 and year%100!=0) or year%400==0

def totalDays(year,month,day):
    total = year*365+day
    for i in range(0,month+1):
        total+=months[i]
    if isLeapYear:
        total+=1
    return total

days = totalDays(yearEnd,monthEnd,dayEnd) - totalDays(yearStart,monthStart,dayStart)
print(days)
  • There are [good reasons](https://stackoverflow.com/questions/6841333/why-is-subtracting-these-two-times-in-1927-giving-a-strange-result/6841479#6841479) to use built in functions, however the duplicate has other answers that dont use built ins – Sayse May 10 '21 at 14:49
  • As the duplicate does not have the constraint that no builtin function should be used, I have posted there [an answer](https://stackoverflow.com/a/67474227/5459839) that may be what you are looking for. – trincot May 10 '21 at 16:30

0 Answers0