SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Development resources, articles, tutorials, code samples, tools and downloads for ASP.Net, SQL Server, Reporting Services, T-SQL, Windows, AWS, SAP HANA and ABAP


SQL Server EOMonth End of Month Function to Calculate Last Day of Month

SQL Server EOMonth() function returns the last day of the month that the input argument start_date is in that month. There is an optional input parameter offset, which helps T-SQL developers to find the end of month that is N months later or before the input start date argument. The default value of offset parameter month to add or month to substract is 0.

EOMONTH (start_date [, month_to_add])
Code

SQL EOMonth datetime function is first introduced to SQL Server developers with the release of SQL Server 2012.

Here is a few SQL code where the new datetime function EOMonth is used to calculate the last date of the month where the input date parameter is in

DECLARE @current_date DATETIME = GETDATE()
SELECT EOMONTH (@current_date) AS 'The last date of Current Month'
Code

SQL last date of month calculation in SQL Server 2012

Now T-SQL programmers can pass the offset argument value of the SQL EOMonth function, instead of the default 0 value.

DECLARE @current_date DATETIME = GETDATE()
SELECT
 EOMONTH (@current_date, -1) AS 'The last date of Previous Month',
 EOMONTH (@current_date) AS 'The last date of Current Month',
 EOMONTH (@current_date, 1) AS 'The last date of Next Month'
Code

SQL EOMonth() datetime function for end of month calculation



SQL Server

SQL Server 2019 Installation
download SQL Server 2019
download SQL Server 2017
download SQL Server 2016
download SQL Server 2014
download SQL Server 2012
MacOS ve SQL Server 2019


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.