導入包
from django.utils.timezone import now #時間
import datetime #時間
now_time = datetime.datetime.now() #獲取當前時間
day_num = now_time.isoweekday() #當前天是這周的第幾天
week_start = ((now_time - datetime.timedelta(days=day_num)) + datetime.timedelta(days=1)).date() #計算當前天所在周周一 格式為yyyy-MM-dd
week_end = ((now_time - datetime.timedelta(days=day_num)) + datetime.timedelta(days=7)).date() #計算當前天所在周周天 格式為yyyy-MM-dd
print(week_end)
week_e = ((now_time - datetime.timedelta(days=day_num)) + datetime.timedelta(days=7)) #計算當前天所在周周天 格式為yyyy-MM-dd 12:01:13.026315
week_s = ((now_time - datetime.timedelta(days=day_num)) + datetime.timedelta(days=1))#計算當前天所在周周一 格式為yyyy-MM-dd 12:01:13.026315
while week_s <= week_e: #循環輸出周一至周五的每天日期格式yyyy-MM-dd
print(week_s.date())
week_s = week_s + datetime.timedelta(days=1)
create_time__range=(week_start, week_end) #范圍(周一,周五)可用於數據庫日期范圍查詢
print(create_time__range)
