from datetime import datetime, timedelta
def get_date_range():
today = datetime.now().date()
if today.day == 1:
if today.month == 1:
first_day_of_last_month = today.replace(year=today.year-1, month=12, day=1)
else:
first_day_of_last_month = today.replace(month=today.month-1, day=1)
last_day_of_last_month = today - timedelta(days=1)
start_date = first_day_of_last_month
end_date = last_day_of_last_month
else:
first_day_of_current_month = today.replace(day=1)
end_date = today - timedelta(days=1)
start_date = first_day_of_current_month
start_date_str = start_date.strftime("%Y-%m-%d")
end_date_str = end_date.strftime("%Y-%m-%d")
return start_date_str, end_date_str
start_date, end_date = get_date_range()
print(f"开始日期: {start_date}")
print(f"结束日期: {end_date}")
以上是一个简单的日期判断条件,我想用我自定义出来的这个变量开始日期和结束日期,我发现打印说我没有定义变量,这还怎么定义?