■ 특정일이 속하는 월(Month)의 첫번째 날짜 구하기

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

import datetime

 

def GetMonthFirstDate(sourceDate):

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

    return targetDate

 

if __name__ == "__main__":

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

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

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

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요