첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
본 블로그는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 블로그 콘텐츠 향상을 위해 쓰여집니다.

728x90
반응형
728x170
import datetime

def AddDays(sourceDate, count):
    targetDate = sourceDate + datetime.timedelta(days = count)
    return targetDate

def GetWeekLastDate(sourceDate):
    temporaryDate = datetime.datetime(sourceDate.year, sourceDate.month, sourceDate.day)
    weekDayCount = temporaryDate.weekday()
    targetDate = AddDays(sourceDate, -weekDayCount + 6);
    return targetDate

if __name__ == "__main__":
    print(GetWeekLastDate(datetime.datetime(2016, 2 , 21))) # 2016-02-21 00:00:00
    print(GetWeekLastDate(datetime.datetime(2016, 2 , 22))) # 2016-02-28 00:00:00
    print(GetWeekLastDate(datetime.datetime(2016, 2 , 23))) # 2016-02-28 00:00:00
    print(GetWeekLastDate(datetime.datetime(2016, 2 , 24))) # 2016-02-28 00:00:00
    print(GetWeekLastDate(datetime.datetime(2016, 2 , 25))) # 2016-02-28 00:00:00
    print(GetWeekLastDate(datetime.datetime(2016, 2 , 26))) # 2016-02-28 00:00:00
    print(GetWeekLastDate(datetime.datetime(2016, 2 , 27))) # 2016-02-28 00:00:00
    print(GetWeekLastDate(datetime.datetime(2016, 2 , 28))) # 2016-02-28 00:00:00
    print(GetWeekLastDate(datetime.datetime(2016, 2 , 29))) # 2016-03-06 00:00:00
    print(GetWeekLastDate(datetime.datetime(2016, 3 , 1 ))) # 2016-03-06 00:00:00

    print(GetWeekLastDate(datetime.datetime(2019, 11, 9 ))) # 2019-11-10 00:00:00
    print(GetWeekLastDate(datetime.datetime(2019, 11, 10))) # 2019-11-10 00:00:00
    print(GetWeekLastDate(datetime.datetime(2019, 11, 11))) # 2019-11-17 00:00:00
    print(GetWeekLastDate(datetime.datetime(2019, 11, 12))) # 2019-11-17 00:00:00
    print(GetWeekLastDate(datetime.datetime(2019, 11, 13))) # 2019-11-17 00:00:00
    print(GetWeekLastDate(datetime.datetime(2019, 11, 14))) # 2019-11-17 00:00:00
    print(GetWeekLastDate(datetime.datetime(2019, 11, 15))) # 2019-11-17 00:00:00
    print(GetWeekLastDate(datetime.datetime(2019, 11, 16))) # 2019-11-17 00:00:00
    print(GetWeekLastDate(datetime.datetime(2019, 11, 17))) # 2019-11-17 00:00:00
    print(GetWeekLastDate(datetime.datetime(2019, 11, 18))) # 2019-11-24 00:00:00
728x90
반응형
그리드형
Posted by 사용자 icodebroker

댓글을 달아 주세요