Python Forum
Calendar calcualtions
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calendar calcualtions
#1
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.
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
Reply


Messages In This Thread
Calendar calcualtions - by deusvult - Apr-28-2017, 09:54 PM
RE: Calendar calcualtions - by wavic - Apr-28-2017, 10:06 PM
RE: Calendar calcualtions - by deusvult - Apr-28-2017, 10:09 PM
RE: Calendar calcualtions - by wavic - Apr-28-2017, 10:11 PM
RE: Calendar calcualtions - by deusvult - Apr-28-2017, 10:39 PM
RE: Calendar calcualtions - by wavic - Apr-28-2017, 11:04 PM
RE: Calendar calcualtions - by Ofnuts - Apr-30-2017, 08:55 PM
RE: Calendar calcualtions - by volcano63 - Apr-28-2017, 10:38 PM
RE: Calendar calcualtions - by zivoni - Apr-28-2017, 10:39 PM
RE: Calendar calcualtions - by Larz60+ - May-01-2017, 12:00 AM
RE: Calendar calcualtions - by volcano63 - May-01-2017, 01:31 AM
RE: Calendar calcualtions - by nilamo - May-01-2017, 02:56 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Task calendar problem humanical 8 2,076 Sep-04-2023, 02:55 PM
Last Post: Pedroski55
  Calendar program louienyy 2 5,144 Mar-30-2020, 01:21 PM
Last Post: louienyy
Sad [Learning] Calendar without modules or list KoFu 5 5,050 Sep-09-2019, 03:25 PM
Last Post: DeaD_EyE
  Calendar calculations frequency 10 5,929 Nov-13-2018, 07:34 PM
Last Post: frequency

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020