Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Days Between by CyprianSzlachciak
def czy_przest(a):
if (a%4==0 and a%100!=0) or a%400==0:
return True
return False
def poszczegolne(a):
if czy_przest(a)==False:
return [31,28,31,30,31,30,31,31,30,31,30,31]
else:
return [31,29,31,30,31,30,31,31,30,31,30,31]
def idoC(x):
s=0
for i in range(0,x[0]):
if czy_przest(i)==True:
s+=366
else:
s+=365
p=poszczegolne(x[0])
for i in range(0,x[1]-1):
s+=p[i]
s+=x[2]
return s
def days_diff(date1, date2):
"""list1=[]
list2=[]
for i in range(0,3):
list1[i]=date1[i]
list2[i]=date2[i] """
return abs(idoC(date1)-idoC(date2))
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
Nov. 21, 2016