Find Last Day of Next Month + SQL Server 2012

Bandi
Posted by Bandi under Sql Server category on | Points: 40 | Views : 341
If positive value is specified as 2nd argument for EOMONTH function; then it will add specified number of months to the given date and then returns last date of tha month...

SELECT 1 AS NO_OF_MONTH,GETDATE() AS InputDate,EOMONTH(GETDATE(),1)AS Result
UNION ALL
SELECT 2 AS NO_OF_MONTH,GETDATE() AS InputDate,EOMONTH(GETDATE(),2)AS Result
UNION ALL
SELECT 6 AS NO_OF_MONTH,GETDATE() AS InputDate,EOMONTH(GETDATE(),6)AS Result
UNION ALL
SELECT -4 AS NO_OF_MONTH,GETDATE() AS InputDate,EOMONTH(GETDATE(),-4)AS Result
UNION ALL
SELECT 12 AS NO_OF_MONTH,GETDATE() AS InputDate,EOMONTH(GETDATE(),12)AS Result
UNION ALL
SELECT -12 AS NO_OF_MONTH,GETDATE() AS InputDate,EOMONTH(GETDATE(),-12)AS Result


OutPut
NO_OF_MONTH	InputDate	        Result 
1 2015-03-20 12:32:09.197 2015-04-30
2 2015-03-20 12:32:09.197 2015-05-31
6 2015-03-20 12:32:09.197 2015-09-30
-4 2015-03-20 12:32:09.197 2014-11-30
12 2015-03-20 12:32:09.197 2016-03-31
-12 2015-03-20 12:32:09.197 2014-03-31

Comments or Responses

Login to post response