简体   繁体   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?

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.

相关问题 MYSQL从当前年份,当前月份和一周中的变量日期获取日期 - MYSQL Get the date from the current year, current month and variable day of the week 如何在单个 mysql 查询中获取当天、当周、当月、当年的销售额总和? - How can i get current day, current week, current month, current year sales sum in single mysql query? 获取星期几,星期几,月份和年份的日期 - Get Date with Day of Week, Week Number, Month and Year MySQL:根据特定月/年的第 n 天获取日期 - MySQL: Get date based on the nth day of the week on a particular month/year 假设每月的第一个星期一是去年该月的第一个星期一,如何计算上一年的同一天 - How to calculate previous year same day of week from month suppose first Monday of month would be last year first Monday of that month SQL:获取基于当前年份周的第一天 - SQL: get first day of the current year week based 获取当前年度第一个月和第一天的SQL - Get current year first month and first day in SQL SQL中如何将年周转为年月日? - How to Convert Year-Week to Year-Month-Day in SQL? 如何从提供的日期或从当月的GetDate()获取任何月份的上周X天的日期 - How to get date of last week's X day for any month from provided date or from GetDate() for current month 当前月份和年份的特定日期 - Specific day of current month and year
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM