根据13个星期(91天)的滚动季度来计算当前季度的Fiscal_start日期

时间:2020-05-19 16:22:38

标签: sql date oracle-sqldeveloper calculation

我正在寻找一个可在Oracle Developer SQL中使用的SQL解决方案,该解决方案将基于sysdate来计算当前季度的开始和结束日期,并且会计日历将从2020年2月1日开始。每个季度为固定的13周( 91天)-并非3个月,因此每年的财务日历会有所不同。
代码将上传到自动报告中,并且不想每年对其进行调整。 随附本年度会计日历作为示例说明。 Current Fiscal Calendar

我开始走这条路,但是当我意识到这种格式的开始日期不正确时迷路了。

最终解决方案将用于where子句以确定报告日期范围,例如 (其中Report_Date位于Modified_Quarter_Start和sysdate之间)

select trunc(add_months(add_months(trunc(sysdate,'Y') -1 ,
to_number(to_char(sysdate,'Q')) * 3),-1),'MM') 
start_date,trunc(add_months(add_months(trunc(sysdate,'Y') -1 ,
to_number(to_char(sysdate,'Q')) * 3),+2),'MM')-1 Endd_date,
add_months(trunc(sysdate,'Y') -1 ,to_number(to_char(sysdate,'Q')) * 3) end_date ,
to_char(sysdate,'YYYY - q') qtr from dual

非常感谢您的协助。

1 个答案:

答案 0 :(得分:0)

发布,以防将来有人遇到相同的谓词。 在另一个线程中阅读了固定日期的案例声明后,我想到了这种解决方案。

Select Trunc(sysdate - to_date('02-Feb-2019')), 
Case When Trunc(sysdate - to_date('02-Feb-2019')) > 91 Then to_date('02-Feb-2019') + 
Round( to_number(Trunc(sysdate - to_date('02-Feb-2019'))/91),0) * 91 
Else null End Current_Quarter_Start, 
Case When Trunc(sysdate - to_date('02-Feb-2019')) > 91 Then to_date('02-Feb-2019') + 
( (Round( to_number(Trunc(sysdate - to_date('02-Feb-2019'))/91),0) +1 )* 91)-1 Else null End Current_Quarter_End From Dual 
相关问题