Wednesday, April 26, 2017

How to Find First and Last Day of a month with EOMONTH function


      To solve this problem in old days, we had to use DATEADD function to calculate first or last day of a month. SQL Server 2012 has a built-in function named EOMONTH to handle this for you.
EOMONTH(inputdate [,month_to_add])
Let's try to find the last day of January 2017 by using EOMONTH function


Function will add/subtract month_to_add option to inputdate if it's available.


To find a first day of a month, we need use DATEADD function with EOMONTH function.


Here is the first and the last day of January 2017

No comments:

Post a Comment