简体   繁体   English

从日期 ORACLE SQL 中提取财政年度的周

[英]Extract Week of Fiscal year from Date ORACLE SQL

My Fiscal Year start from 1st july to 30 June.I want to calculate weeks from start of Financial year for a year.我的财政年度从 7 月 1 日到 6 月 30 日开始。我想从财政年度开始计算一年的周数。 WEEK1,WEEK2 WEEK3...WEEK 52 ETC第 1 周,第 2 周 第 3 周...第 52 周等

Following will give you week number in a number datatype以下将以number数据类型为您提供周数

to_number(to_char(to_date('07/01/2019','MM/DD/YYYY'),'WW')) as week_num

and if you want week based on ISO standard the use following如果您想要基于 ISO 标准的一周,请使用以下

to_number(to_char(to_date('07/01/2019','MM/DD/YYYY'),'IW')) as week_num

Try this:尝试这个:

FLOOR(theDate - TO_DATE('07/01/2019','MM/DD/YYYY')) / 7) + 1 AS FISCAL_WEEK

where theDate is a date between 07/01/2019 and 06/30/2020.其中theDate是介于 07/01/2019 和 06/30/2020 之间的日期。

You can use conditional logic:您可以使用条件逻辑:

select (case when extract(month from sysdate) < 7
             then floor((sysdate - trunc(sysdate, 'YYYY')) / 7) + 1
             else floor((sysdate - (trunc(sysdate, 'YYYY') + interval '6' month))/7) + 1
        end) as fiscal_week

This uses sysdate to represent the date.这使用sysdate来表示日期。 You can, of course, replace it with your date column.当然,您可以将其替换为您的日期列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM