python获取上周的起始日期

import datetime


def get_date_of_last_week(form='%Y-%m-%d'):
    """
    获取上周开始结束日期
    :param form: 日期格式
    :return: str,date tuple
    """
    today = datetime.date.today()
    begin_of_last_week = (today - datetime.timedelta(days=today.isoweekday() + 7)).strftime(form)
    end_of_last_week = (today - datetime.timedelta(days=today.isoweekday() + 1)).strftime(form)
    return begin_of_last_week, end_of_last_week
posted @ 2021-08-19 21:00  Rong_Z  阅读(490)  评论(0编辑  收藏  举报