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

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

import datetime

 

def GetQuaterFirstDate(sourceDate):

    if   sourceDate.month < 4  : targetMonth = 1

    elif sourceDate.month < 7  : targetMonth = 4

    elif sourceDate.month < 10 : targetMonth = 7

    else                       : targetMonth = 10

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

    return targetDate

 

if __name__ == "__main__":

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

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

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

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요