Thursday, November 17, 2016

EOMONTH() New Date Function In 2012

it is the new date time function in sql server 2012 and and higher versions.It cannot be remoted to servers with a version lower than SQL Server 2012.
Definition:
    Returns the last day of the month that contains the specified date, with an optional offset.
syntax :
  EOMONTH ( start_date [, month_to_add ] )  
Examples:
DECLARE @date DATETIME = '12/1/2011';
SELECT EOMONTH ( @date ) AS Result;
GO
    Result :   2011-12-31  
DECLARE @date VARCHAR(255) = '12/1/2011';
SELECT EOMONTH ( @date ) AS Result;
GO
    Result : 2011-12-31 
DECLARE @date DATETIME ='2011-12-01';
SELECT EOMONTH ( @date ) AS 'This Month';
SELECT EOMONTH ( @date, 1 ) AS 'Next Month';
SELECT EOMONTH ( @date, -1 ) AS 'Last Month';
GO
result
-----------------------
2011-12-31
(1 row(s) affected)
Next Month
-----------------------
2012-01-31
(1 row(s) affected)
2011-11-30
Last Month
-----------------------
(1 row(s) affected)
--> By using EOMONTH function to easyly get perticuar month last date.
                                                                          థాంక్స్ ,
                                                                          బాబ్జి రెడ్డి జి వి

No comments:

Post a Comment