python 获取上个月第一天和最后一天
# 获取上个月第一天和最后一天 def get_last_month_first_last_day(date_param: datetime): """ :param date_param: 接受一个日期参数 datetime类型 :return: 返回上个月第一天和最后一天 """ if not isinstance(date_param, datetime.datetime): raise TypeError("Please pass the <class 'datetime.datetime'>") m_last_day = datetime.date(date_param.year, date_param.month, 1) - datetime.timedelta(days=1) m_first_day = datetime.date(m_last_day.year, m_last_day.month, 1) return m_first_day, m_last_day