# -*- coding: utf-8 -*- """ Created on Fri Sep 23 20:42:58 2022 @author: Administrator """ import time import datetime def days360(start_date, end_date, method_eu=False): """ 功能:同excel中函数,=DAYS360(B452,A452,0) """ start_date = datetime.datetime.strptime(start_date,"%Y-%m-%d") end_date = datetime.datetime.strptime(end_date,"%Y-%m-%d") start_day = start_date.day start_month = start_date.month start_year = start_date.year end_day = end_date.day end_month = end_date.month end_year = end_date.year if ( start_day == 31 or ( method_eu is False and start_month == 2 and ( start_day == 29 or ( start_day == 28 and ((start_year%4==0) and (start_year%100 !=0) or (start_year%400)==0) #闰年 ) ) ) ): start_day = 30 if end_day == 31: if method_eu is False and start_day != 30: end_day = 1 if end_month == 12: end_year += 1 end_month = 1 else: end_month += 1 else: end_day = 30 return ( end_day + end_month * 30 + end_year * 360 - start_day - start_month * 30 - start_year * 360) days360('2020-02-28','2021-02-22')
标签:end,函数,python,day,start,year,date,month,days360 From: https://www.cnblogs.com/andylhc/p/16731083.html