How to find last day and first day of a month in Oracle

In Oracle, you can use the LAST_DAY function to find the last day of a given month. Here’s how:

1. Basic Query

SELECT LAST_DAY(SYSDATE) AS last_day_of_current_month FROM DUAL;

✅ This returns the last day of the current month.


2. For a Specific Date

If you want the last day of a specific month, replace SYSDATE with your desired date:

SELECT LAST_DAY(TO_DATE('15-FEB-2024', 'DD-MON-YYYY')) AS last_day_of_feb FROM DUAL;

✅ This will return 29-FEB-2024 (since 2024 is a leap year).


3. Finding the Last Day of a Specific Year and Month

SELECT LAST_DAY(TO_DATE('01-07-2024', 'DD-MM-YYYY')) AS last_day_of_july FROM DUAL;

✅ This will return 31-JUL-2024.


4. Using LAST_DAY with TRUNC for Month Start & End

SELECT
TRUNC(SYSDATE, 'MM') AS first_day_of_month, LAST_DAY(SYSDATE) AS last_day_of_month FROM DUAL;

✅ This will return:

  • First day of the current month.
  • Last day of the current month.

Post a Comment

And that's all there is to it!

If anyone has any other questions or requests for future How To posts, you can either ask them in the comments or email me. Please don't feel shy at all!

I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.

Previous Post Next Post