如何计算最近5个财政年度的最后截止日期?需结合当前日期与3月31日判断
最近5个财政年度最后截止日期计算规则
财年默认以每年3月31日为截止节点,最近5个财年截止日的判断规则如下:
- 若当前日期晚于当年3月31日,输出结果为:2021年3月31日、2020年3月31日、2019年3月31日、2018年3月31日、2017年3月31日
- 若当前日期早于当年3月31日,输出结果为:2020年3月31日、2019年3月31日、2018年3月31日、2017年3月31日、2016年3月31日
上述固定年份为当前日期在2021-2022年区间的示例输出,如需适配任意时间的通用计算,核心逻辑为:先判断当前日期是否超过当年3月31日,超过则基准年取当前年,未超过则基准年取当前年减1,再从基准年开始往前倒推5年,每年取3月31日即可。
参考Python实现代码如下:
import datetime def get_recent_5_fy_end_dates(): today = datetime.date.today() curr_year = today.year year_cutoff = datetime.date(curr_year, 3, 31) base_year = curr_year if today > year_cutoff else curr_year - 1 return [datetime.date(base_year - i, 3, 31) for i in range(5)]
内容的提问来源于stack exchange,提问作者Akshay Gaikwad
相关产品推荐
相关产品推荐

