如何创建两个变量。
1 -上个月的变量
2 -过去 10 个月的变量
就像代表 TODAY - 10 个月的日期一样,例如:2020/02/05 - 10 months = 2019/04/05
.
我的代码:
import datime
# 1- last month
month = datetime.datetime.now().month
year = datetime.datetime.now().year
last_month = f"{year}/{month-1}/01"
>>>
"2020/01/05"
# Past 12 months
past_10month = datetime.datetime.today()
past_10month = f"{past_10month -285}"
>>>
# DO NOT WORK
# EXPECTED RESULT:
# "2019/04/05"
一只斗牛犬
相关分类