SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

SQL Server 2012 – Enter the EOMONTH Function

In this blog post, I will be sharing a new date feature in SQL Server 2012 called the EOMONTH (End of Month) which is used to find or get the last day of a month in a specified date.

In prior versions of SQL Server 2012, date functions like “dateadd” and/or “datediff” were invaluable in finding the last day of a month.

Consider a SQL Server 2005/2008 R2 example of how we find the last day of a month;


The use of the date functions in the example above returns a date value of 2012-08-31 00:00:00.000 (see red arrow).

Now this same result can be achieved by using the EOMONTH function in SQL Server 2012 as shown below;



SET @date = ‘20120802’


This returns ‘2012-02-31’


Thanks for reading and hope you’ve gained something.



For additional reading, please see http://msdn.microsoft.com/en-us/library/hh213020.aspx


Ziek's SQL Home

Ezekiel is an IT professional with over ten years experience in building database applications and BI solutions. He holds a BSc Computer Science degree from KNUST, Ghana and a MSc Business IT degree from Kingston Business School, London. He has delivered solutions for the Insurance, Banking, Telecom and Housing Industries and his key expertise include developing Microsoft BI solutions using the full stack and C#, Business Process Improvement and Project Risk Management. He is a Microsoft SQL Server Certified Professional.


Leave a comment on the original post [learnsqlwithezekiel.wordpress.com, opens in a new window]

Loading comments...