Identifying the number of days in a month using LAST_DAY
The LAST_DAY
function returns the last day of the month based on the input date value (date_val
). This is easy, right? January has 31 days and December has 31 days. However, what about February? Refer to the leap year. Thus, as is evident, this particular function is really useful and it must be available.
The syntax of this function can be seen in the following code block:
LAST_DAY(<date_val>)
The following statement provides you with the last day of October:
select LAST_DAY(TO_DATE('10.1.2022', 'DD.MM.YYYY')) from dual; --> 31.01.2022
Naturally, it also manages leap years. The year 2023 is not a leap year, but the year 2024 is a leap year:
select LAST_DAY(TO_DATE('15.2.2023', 'DD.MM.YYYY')) from dual; --> 28.2.2023 select LAST_DAY(TO_DATE('15.2.2024', 'DD.MM.YYYY')) from dual; --> 29.2.2024
When...