Apr-28-2017, 09:54 PM
(This post was last modified: Apr-28-2017, 10:03 PM by sparkz_alot.)
Hi!
I am trying to calculate difference in days between two dates. If the dates are close enough the answer is correct but as the difference increases I start getting an error.
I know there is a different way how to do it, but I would appreciate help in spotting whats wrong in this one.
I am trying to calculate difference in days between two dates. If the dates are close enough the answer is correct but as the difference increases I start getting an error.
I know there is a different way how to do it, but I would appreciate help in spotting whats wrong in this one.
print "***Calendar simulator 2.0***" print d1,m1,y1 = map(int,raw_input("Enter start date in DD.MM.YYYY format: ").split(".")) print d2,m2,y2 = map(int,raw_input("Enter end date in DD.MM.YYYY format: ").split(".")) print m111=m1-1 m222=m2-1 y11 = int((y1-1)/4.)+(y1-1)*365 if (y1)/4. == float(int((y1)/4.)): a = [31,29,31,30,31,30,31,31,30,31,30,31] else: a = [31,28,31,30,31,30,31,31,30,31,30,31] m11 = sum(a[0:m111]) x = y11+m11+d1 y22 = int((y2-1)/4.)+(y2-1)*365 if (y2)/4. == float(int((y2)/4.)): b = [31,29,31,30,31,30,31,31,30,31,30,31] else: b = [31,28,31,30,31,30,31,31,30,31,30,31] m22 = sum(b[0:m222]) y = y22+m22+d2 diff = abs(y-x) s = (diff % 10) if s == 1: print "Difference is: ", diff, " day." print print "Ready." else: print"Difference is: ", diff, " days." print print "Ready." print x print y