今天时2023-4-19,我想获取上个季度的起始日期,就再chatgpt上问了下
from datetime import date, timedeltadef get_last_quarter_dates():today = date.today()month = (today.month - 1) % 3last_quarter_end = date(today.year, month + 1, 1) - timedelta(days=1)last_quarter_start = date(last_quarter_end.year, last_quarter_end.month - 2, 1)return last_quarter_start, last_quarter_end
结果返回的时上上个季度的,这段代码没有考虑跨年,肯定时不对的
chatgpt的代码可以做参考,不能作为最终标准