■ 특정 주차(Week Number)의 마지막 날짜 구하기

------------------------------------------------------------------------------------------------------------------------

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

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요