To get the first date of the current month:
select sysdate “date” from dual /*Current Date */
union all
select trunc(sysdate,’MONTH’) from dual /*getting first day of the month*/
Result:
04-Mar-2021
01-Mar-2021
To get the last date of the current month:
select sysdate “date” from dual–sysdate
union all
select trunc(last_day(sysdate)) from dual–getting last day of the current month
Result:
04-Mar-2021
31-Mar-2021
To determine how many days are left in the current month:
SELECT
last_day(SYSDATE) – SYSDATE AS no_of_days_left,
SYSDATE today_date
FROM
Dual
Result:
no_of_days_left today_date
27 04-Mar-2021
To get the firsts and last day of the year :
select trunc(sysdate,’Year’) from dual–first date of the year
union all
select add_months(trunc(sysdate,’year’),12)-1 from dual –last day of the year
Result:
01-Jan-21
31-Dec-21
To get the number of days in current month:
SELECT
CAST(TO_CHAR(last_day(SYSDATE),’dd’) AS INT) “Days_in_months”
FROM
Dual
Result:
Days_in_months
31
To get number of days between two given dates:
SELECT
round(months_between(’31-mar-2021′,’01-jan-2021′) * 30,0) “diff_days”
FROM
Dual
Result:
diff_days
89