■ 특정일이 속하는 분기(Quater)의 마지막 날짜 구하기
------------------------------------------------------------------------------------------------------------------------
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
------------------------------------------------------------------------------------------------------------------------
'Python > datetime' 카테고리의 다른 글
[PYTHON/DATETIME] 특정 주차(Week Number)의 마지막 날짜 구하기 (0) | 2019.11.16 |
---|---|
[PYTHON/DATETIME] 특정 주차(Week Number)의 첫번째 날짜 구하기 (0) | 2019.11.16 |
[PYTHON/DATETIME] 특정일이 속하는 주차(Week Number) 구하기 (0) | 2019.11.16 |
[PYTHON/DATETIME] 특정일이 속하는 연도(Year)의 마지막 날짜 구하기 (0) | 2019.11.16 |
[PYTHON/DATETIME] 특정일이 속하는 연도(Year)의 첫번째 날짜 구하기 (0) | 2019.11.16 |
[PYTHON/DATETIME] 특정일이 속하는 분기(Quater)의 마지막 날짜 구하기 (0) | 2019.11.16 |
[PYTHON/DATETIME] 특정일이 속하는 분기(Quater)의 첫번째 날짜 구하기 (0) | 2019.11.16 |
[PYTHON/DATETIME] 특정일이 속하는 월(Month)의 마지막 날짜 구하기 (0) | 2019.11.16 |
[PYTHON/DATETIME] 특정일이 속하는 월(Month)의 첫번째 날짜 구하기 (0) | 2019.11.16 |
[PYTHON/DATETIME] 특정일이 속하는 주(Week)의 마지막 날짜(일요일) 구하기 (0) | 2019.11.16 |
[PYTHON/DATETIME] 특정일이 속하는 주(Week)의 첫번째 날짜(월요일) 구하기 (0) | 2019.11.16 |
댓글을 달아 주세요