Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
aw yas solution in Clear category for Days Between by Adrian_W
def areEqual(a,b):
for i in range (0,3):
if a[i]!=b[i]:
return False
return True
def whichOlder(a,b):
for i in range (0,3):
if a[i]>b[i]:
return 0
elif b[i]>a[i]:
return 1
return -1
def iterate(a):
months={1:31,2:28,3:31,4:30,5:31,6:30,7:31,8:31,9:30,10:31,11:30,12:31}
if (a[0]%4==0 and a[0]%100!=0) or a[0]%400==0:
months[2]=29
if a[2]12:
a[0]+=1
a[1]=1
return a
def days_diff(date1, date2):
days=0
dateA=[date1[0],date1[1],date1[2]]
dateB=[date2[0],date2[1],date2[2]]
older=whichOlder(dateA, dateB)
#equal dates
if older==-1:
return 0
while areEqual(dateA,dateB)!=True:
if older==1:
days+=1
dateA=iterate(dateA)
else:
days+=1
dateB=iterate(dateB)
return days
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert days_diff((1982, 4, 19), (1982, 4, 22)) == 3
assert days_diff((2014, 1, 1), (2014, 8, 27)) == 238
assert days_diff((2014, 8, 27), (2014, 1, 1)) == 238
Oct. 15, 2016