Date/Time Functions – EOMONTH()

I linger on to the end with my writing of short articles or tidbits on Transaction SQL date/time functions.

Most, if not all, modern day computer systems collect data which contains dates and times.

Sometimes we want to know the start date and end date of each month. Before SQL Server 2012, you used to have to set the date to the first of next month. Then use the DATEADD() function to back date by one day to get the end of month date.

Today, I will be exploring the EOMONTH() function that takes a start date and optional months to add as input and returns the end of the month as a date.

The examples below are sample calls to the function. All inputs are valid or positive test cases.

The output from the test is listed below.

The following rules apply when dealing with negative test cases or invalid data. Any invalid date parameter results in a raised error. Any NULL values passed as parameters result in a NULL result. Any EMPTY strings result in a default date.

In a nutshell, the end of month function EOMONTH() is a brand new function that can save you some typing. However, it is only available in SQL Server 2012 or greater.

Related posts

Leave a Comment