跳到内容
🛠️ToolsShed

Quarters Calculator

查找任何日期的财政或日历季度,包括开始/结束日期和经过的天数。

关于此工具

季度计算器帮助你确定任何日期属于哪一个会计季度或日历季度,并提供该季度的开始日期、结束日期以及已经过去的天数。这个工具对业务专业人士、会计师以及需要按季度周期组织工作、预算或报告的人特别有用。

只需输入或选择任何日期,工具就会即时显示季度标记(Q1、Q2、Q3 或 Q4)、该季度的准确开始和结束日期,以及从季度开始到选定日期的经过天数。你可以在日历季度(1月-3月、4月-6月、7月-9月、10月-12月)和具有自定义开始月份的会计季度之间切换。

这个工具非常适合财务规划、项目里程碑追踪、税务准备以及与季度周期对齐的绩效评估。无论你需要确定销售交易发生在哪一个季度,还是计划围绕季度截止日期的交付物,这个计算器都能消除猜测并节省时间。

常见问题

代码实现

from datetime import date, timedelta
import calendar

def calendar_quarter(d):
    """Return Q1-Q4 for a calendar year date"""
    return (d.month - 1) // 3 + 1

def fiscal_quarter(d, fiscal_start_month=1):
    """Return fiscal quarter given fiscal year start month"""
    offset = (d.month - fiscal_start_month) % 12
    return offset // 3 + 1

def quarter_dates(year, q, fiscal_start_month=1):
    """Return (start, end) dates for a given fiscal quarter"""
    start_month = ((fiscal_start_month - 1 + (q - 1) * 3) % 12) + 1
    start_year = year if start_month >= fiscal_start_month else year - 1
    start = date(start_year, start_month, 1)
    # End = last day of 3rd month
    end_month = (start_month - 1 + 3 - 1) % 12 + 1
    end_year = start_year if end_month >= start_month else start_year + 1
    end = date(end_year, end_month, calendar.monthrange(end_year, end_month)[1])
    return start, end

d = date.today()
q = calendar_quarter(d)
start, end = quarter_dates(d.year, q)
print(f"Q{q}: {start} to {end}")
print(f"Days elapsed: {(d - start).days + 1}")
print(f"Days remaining: {(end - d).days}")

# Fiscal year starting April (UK standard)
fq = fiscal_quarter(d, fiscal_start_month=4)
print(f"UK Fiscal Q{fq}")

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.