繁体   English   中英

我怎样才能得到从当天,当月或当年的第一天到当天的一周,一个月或一年的日期?

[英]How could I get the the date of the week, month or year starting from the first day up to the current day of the current week, month or year?

如果标题令人困惑,我很抱歉。 基本上我正在使用Oracle Apex 18.x创建一个仪表板,在我的卡中,我比较今天与昨天,本周与上周,本月与上个月和今年与去年的销售额。

今天与昨天我没有问题。 我的问题是一周,一个月和一年,因为我想只比较当天,而不是整个上周。

例如,如果今天是本周的第4天,那么我必须将它从上周到第4天进行比较。

对于本月,如果我们说今天是2018年3月25日,那么我应该只将其与2月份的1-25月份进行比较。 与年份相同。

如果要求是上周,上个月和去年全部完整,这不会是一个问题。

week我会这样做:

select 
TRUNC(sysdate, 'DAY') start_of_the_week,
(sysdate) day_of_current_week,
(TRUNC(sysdate, 'DAY') - 7 ) start_of_last_week
(sysdate - 7) day_of_last_week,
from dual;

这个month会是:

select 
(sysdate) day_of_current_month,
TRUNC(sysdate, 'mm') month_start_date,
ADD_MONTHS(sysdate,-1) day_of_last_month,
ADD_MONTHS(TRUNC(sysdate, 'mm'),-1) start_of_last_month
from dual;

暂无
暂无

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

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