■ 특정일이 속하는 분기(Quater)의 마지막 날짜를 구하는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import datetime def GetQuaterLastDate(sourceDate): if sourceDate.month < 4: targetMonth = 3 targetDay = 31 elif sourceDate.month < 7: targetMonth = 6 targetDay = 30 elif sourceDate.month < 10: targetMonth = 9 targetDay = 30 else: targetMonth = 12 targetDay = 31 targetDate = datetime.datetime(sourceDate.year, targetMonth, targetDay) return targetDate if __name__ == "__main__": print(GetQuaterLastDate(datetime.datetime(2016, 2 , 16))) # 2016-03-31 00:00:00 print(GetQuaterLastDate(datetime.datetime(2019, 11, 16))) # 2019-12-31 00:00:00 |