■ 특정일이 속하는 분기(Quater)의 첫번째 날짜를 구하는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
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 |