■ 특정일이 속하는 연도(Year)의 첫번째 날짜 구하기

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

import datetime

 

def GetYearFirstDate(sourceDate):

    targetDate = datetime.datetime(sourceDate.year, 1, 1)

    return targetDate

 

if __name__ == "__main__":

    print(GetYearFirstDate(datetime.datetime(2016, 2 , 16))) # 2016-01-01 00:00:00

    print(GetYearFirstDate(datetime.datetime(2019, 11, 16))) # 2019-01-01 00:00:00

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

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요