(需要帮助)两个日期之间的时间 w/o Dateti

(Help Needed) Time between two dates w/o Dateti

我必须计算 Python 中两个日期之间的天数,但没有 datetime 模块。

我设法解析了一个没有 datetime 的日期:

def date(error):
    global sdate
    if error:
        print(sdate," isn't a valable date ! ")
    sdate = input('Date : ')
    try:
        ldate = sdate.split('.')
        ldate = [ int(x) for x in ldate]
        day,month,year = ldate
    except ValueError:
        date(True)
    if year%4==0 and year%100!=0 or year%400==0:
        bis = True
    else:
        bis = False
    if month not in range(1,13):
        date(True)
    if month not in(1,3,5,7,8,10,12):
        mmax = 31
    elif month in(4,6,9,11):
        mmax = 30
    elif month == 2 and bis == True:
        mmax = 29
    elif month == 2 and bis == False:
        mmax = 28
    if day not in range(1,mmax+1):
        date(True)
date(None)
print(ldate)

但没有弄清楚如何获取日期之间的时间。

最简单的方法是什么?

谢谢, 布拉索

PS:这根本不是家庭作业,我需要它来进行个人项目,在该项目中我使用了任何过于轻松的生活模块;)

要检查两个日期之间的差异,您要做的远不止这些。

我会给你伪代码来做这个,写你自己的程序。

• get the dates
• validate the dates 
    -> (ex. It should be false for feb 29 2007)
• calculate total number of days of that particular year for both dates 
    -> (ex 1 jan 2015 = 01 and 28 feb 2016 = 59)
• calculate the year difference
• calculate number of leap years between two days (excluding both end)
    -> (2004 and 2008 leap year is 0)
• calculate the difference by
  diff(number of days) + (year difference * 365) + number of leap years