■ 특정일이 속하는 주차(Week Number) 구하기

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

import datetime

 

def GetWeekNumber(sourceDate):

    weekNumber = sourceDate.isocalendar()[1]

    return weekNumber

 

if __name__ == "__main__":

    print(GetWeekNumber(datetime.datetime(2018, 12, 29))) # 52

    print(GetWeekNumber(datetime.datetime(2018, 12, 30))) # 52

    print(GetWeekNumber(datetime.datetime(2018, 12, 31))) # 1

    print(GetWeekNumber(datetime.datetime(2019, 1 , 1 ))) # 1

    print(GetWeekNumber(datetime.datetime(2019, 1 , 7 ))) # 2

    print(GetWeekNumber(datetime.datetime(2019, 1 , 14))) # 3

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

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요