[英]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?
I'm sorry if the title is confusing. 如果标题令人困惑,我很抱歉。 Basically I am creating a dashboard using Oracle Apex 18.x and in one my card, I am comparing the sales between today vs yesterday, this week vs last week, this month vs last month and this year vs last year. 基本上我正在使用Oracle Apex 18.x创建一个仪表板,在我的卡中,我比较今天与昨天,本周与上周,本月与上个月和今年与去年的销售额。
I have no problem with the today vs yesterday. 今天与昨天我没有问题。 My issue is with the week, month and year because I want to compare only up to the current day, not the whole last week. 我的问题是一周,一个月和一年,因为我想只比较当天,而不是整个上周。
For example, if today is the 4th day of the current week, then I'd have to compare it from last week up to its 4th day only as well. 例如,如果今天是本周的第4天,那么我必须将它从上周到第4天进行比较。
For the month, if let's say today is 25-Mar-2018 then I should only compare it to the month of Feb from 1-25 only. 对于本月,如果我们说今天是2018年3月25日,那么我应该只将其与2月份的1-25月份进行比较。 Same with the year. 与年份相同。
It wouldn't be a problem if the requirement is to get the full last week, full last month and full last year. 如果要求是上周,上个月和去年全部完整,这不会是一个问题。
For week
i would do it like: 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;
For month
it would be: 这个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.