The EOMONTH() function is one of the most commonly used functions in reporting and data analysis. For a given date, it returns the month’s last day, with an optional offset.
There are two arguments to the EOMONTH() function:
- start date is a date expression that returns a date when it is evaluated. For this date, the EOMONTH() function returns the last day of the month.
-
month_to_add is an optional integer expression that specifies the number of months to add to start_date.
The EOMONTH() function will produce an error if the combination of offset and start date results in an invalid date.
Examples:
SELECT EOMONTH(‘2022-02-26’) CurrentMonthEndDate;
Returns: 2022-02-28
SELECT EOMONTH(GETDATE()) CurrentMonthEndDate;
Returns: 2022-02-28
SELECT DAY(EOMONTH(GETDATE())) TotalDays;
Returns: 28
SELECT EOMONTH(GETDATE(), 2) LastDayAfter2Months;
Returns: 2022-04-30
Hope you find this article helpful.
Please subscribe for more interesting updates.
2 comments