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

 

    @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

 

上一篇:js 运行时间计算


下一篇:python基础应用:文件备份