Python计算出生日期到今天过了多少天

def Day_of_month(year,month):
    if month==1 or month==3or month==5 or month==7 or month==8 or month==10 or month==10 or month==12:
        day_of_month=31
    elif month!=2:
        day_of_month=30
    elif (year%4==0 and year%100!=0)or(year%400==0):
        day_of_month=29
    else:
        day_of_month=28
    return day_of_month
def Day_of_year(year):
    if (year%4==0 and year%100!=0)or(year%400==0):
        return 366
    else:
        return 365
def Current_pasted_days(year,month,day):
    cur_pDays =0
    for i in range(1,month,1):
        cur_pDays+=Day_of_month(year,i)
    cur_pDays+=day
    return cur_pDays
def dayBetween(y1,m1,d1,y2,m2,d2):
    result=0
    if y1!=y2:
        result+=Day_of_year(y1)-Current_pasted_days(y1,m1,d1)
        for i in range(y1+1,y2,1):
            result+=Day_of_year(i)
        result+=Current_pasted_days(y2,m2,d2)
        return result
    else:
        if m1==m2:
            result+=d2-d1
            return result
        else:
            result+=Day_of_month(y1,d1)-d1
            for i in range(m1+1,m2,1):
                result+=Day_of_month(y1,i)
            result+=d2
            return result
result=dayBetween(1999, 1, 1, 2020, 1,1)
print(result)

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值