Skip Navigation

SQL Last Day of Month

How do I get the last day of the month in a SQL query? Someone recently asked me this question and as with so many questions in development the answer is: it depends.

Prior to SQL Server 2012, this is what typical T-SQL to compute last day of the month would look like:

DECLARE @date DATE = '2017-12-15'; 
DECLARE @firstOfMonth DATE = DATEFROMPARTS(YEAR(@date), MONTH(@date), 1);

With SQL Server 2012 or later, the EOMONTH() gives you a much more concise option which looks like:

DECLARE @date DATE = '2017-12-15'; SELECT EOMONTH(@date)

Previous: How I Cut the Cord