如何获取该周(周一至周日)之后的日期的周日期范围(周一至周日)
how to get week date range (Monday-Sunday) for a date following in between that week(Monday-Sunday)
我希望我给出的特定日期的日期范围是周一到周日。
例如:-
如果我给出“2021-11-22”(星期一)(%Y-%m-%d),那么我应该得到“2021-11-22”到“2021-11-28”的日期范围.
另一个案例:-
如果我给出“2021-11-22”和“2021-11-28”(周一至周日)之间的任何日期。
然后它应该给我 (Monday - Sunday) ("2021-11-22" to "2021-11-28")
的日期范围
def returnDateRange(date):
#date can be anything between "2021-11-22" and "2021-11-28"
listOfDateRange = ["2021-11-22","2021-11-28"]
return listOfDateRange
p_week = datetime.date.today().isocalendar()[1]
p_year = datetime.datetime.today().year
def getDateRangeFromWeek(p_year,p_week):
date_string = str(p_year)+"-W"+str(p_week)+"-1"
print(f'{p_year}-W{int(p_week )}-1')
#firstdayofweek = datetime.datetime.strptime(f'{p_year}-W{int(p_week )}-1', "%Y W%W-%w").date()
firstdayofweek = datetime.datetime.strptime(date_string, "%Y-W%W-%w").date()
lastdayofweek = firstdayofweek + datetime.timedelta(days=6.9)
return firstdayofweek, lastdayofweek```
我希望我给出的特定日期的日期范围是周一到周日。 例如:-
如果我给出“2021-11-22”(星期一)(%Y-%m-%d),那么我应该得到“2021-11-22”到“2021-11-28”的日期范围. 另一个案例:- 如果我给出“2021-11-22”和“2021-11-28”(周一至周日)之间的任何日期。 然后它应该给我 (Monday - Sunday) ("2021-11-22" to "2021-11-28")
的日期范围def returnDateRange(date):
#date can be anything between "2021-11-22" and "2021-11-28"
listOfDateRange = ["2021-11-22","2021-11-28"]
return listOfDateRange
p_week = datetime.date.today().isocalendar()[1]
p_year = datetime.datetime.today().year
def getDateRangeFromWeek(p_year,p_week):
date_string = str(p_year)+"-W"+str(p_week)+"-1"
print(f'{p_year}-W{int(p_week )}-1')
#firstdayofweek = datetime.datetime.strptime(f'{p_year}-W{int(p_week )}-1', "%Y W%W-%w").date()
firstdayofweek = datetime.datetime.strptime(date_string, "%Y-W%W-%w").date()
lastdayofweek = firstdayofweek + datetime.timedelta(days=6.9)
return firstdayofweek, lastdayofweek```