def daysBetweenDates(year1, month1, day1, year2, month2, day2): alter = 0; debug_on = 1; if debug_on: print "Dataset: " , year1, month1, day1, year2, month2, day2 #Monate mit 31 Tagen: month31 = [1, 3, 5, 7, 8, 10, 12] #Monate mit 30 Tagen: month30 = [4, 6, 9, 11] #Test auf Schaltjahr: def testLeapYear(year): if year == 2000: return 1 elif (year/4.0) > (year/4): return 0 else: if (year/100.0) == (year/100): return 0 else: return 1 #ganze Jahre: y_count = year2 while (y_count - 1) - year1 > 0: alter += 365 alter += testLeapYear(y_count - 1) if debug_on: print y_count-1, testLeapYear(y_count - 1) y_count -= 1 if debug_on: print "Alter nach Jahren: " + str(alter) #Schalttag im Geburtsjahr hinzurechnen: if month1 < 3 and year2 > year1: alter += testLeapYear(year1) if debug_on: print year1, testLeapYear(year1) if debug_on: print "Alter nach Test Geburtsjahr: " + str(alter) #Schalttag im Abragejahr hinzurechnen: if month2 > 2: alter += testLeapYear(year2) if debug_on: print "Alter nach Test Abfragejahr: " + str(alter) #Tage im aktellem Monat alter += day2 if debug_on: print "Alter nach Abfragemonat: " + str(alter) #Tage im Geburtsmonat m_count1 = month1 while m_count1 > 0: if month1 in month31: alter += (31 - day1) elif month1 in month30: alter += (30 - day1) else: alter += (28 - day1) m_count1 -= 1 if debug_on: print "Alter nach Tagen im Geburtsmonat: " + str(alter) m_kumul = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334] m_kumul_neg = [334, 306, 275, 245, 214, 184, 153, 122, 92, 61, 31, 0] #Tage ab Geburtsmonat: if year2 > year1: alter += m_kumul_neg[month1 - 1] #Tage vor Abfragemonat: if year2 > year1: alter += m_kumul[month2 - 1] #Abfragejahr = Geburtsjahr -> Monate dazwischen: if year1 == year2: alter += (m_kumul[month2-1] - m_kumul[month1]) print "Sie sind " + str(alter) + " Tage alt." daysBetweenDates(1900,1,1,1999,12,31)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question