zl程序教程

您现在的位置是:首页 >  后端

当前栏目

【Python】计算两个日期相差多少天

Python日期计算 两个 多少 相差
2023-09-11 14:16:50 时间

 

    @staticmethod
    def cha_count(start: str, end: str):
        """
        计算两个日期相差多少天
        @param start: '20210820'
        @param end: '20210827'
        @return: 7
        """
        old = datetime.datetime(int(start[0:4]), int(start[4:6]), int(start[6:8]))
        now = datetime.datetime(int(end[0:4]), int(end[4:6]), int(end[6:8]))
        count = (now - old).days
        print(count)
        return count