■ 특정 주차(Week Number)의 마지막 날짜를 구하는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import datetime def GetWeekNumberLastDate(year, weekNumber): yearFirstDate = datetime.datetime(year, 1, 1) currentDate = yearFirstDate + datetime.timedelta(weeks = weekNumber - 1) targetDate = currentDate - datetime.timedelta(days = currentDate.isoweekday() % 7 - 7) return targetDate if __name__ == "__main__": print(GetWeekNumberLastDate(2019, 1)) # 2019-01-06 00:00:00 print(GetWeekNumberLastDate(2019, 2)) # 2019-01-13 00:00:00 print(GetWeekNumberLastDate(2019, 3)) # 2019-01-20 00:00:00 print(GetWeekNumberLastDate(2019, 4)) # 2019-01-27 00:00:00 print(GetWeekNumberLastDate(2019, 5)) # 2019-02-03 00:00:00 print(GetWeekNumberLastDate(2019, 6)) # 2019-02-10 00:00:00 |