Hello ,
try this
declare @date date
declare @daydifference int
declare @lastday date
set @date='2016-2-12'
set @daydifference=(select datediff(day, dateadd(day, 1-day(@date), @date),
dateadd(month, 1, dateadd(day, 1-day(@date), @date))))
DECLARE @firstDayOfMonth date = CAST( CAST(YEAR(@date) AS varchar(4)) + '-' +
CAST(MONTH(@date) AS varchar(2)) + '-01' AS date)
set @lastday=(select DATEADD(DAY, @daydifference-1,@firstDayOfMonth))
select @lastday
it will show '2016-2-29' as output
thanks