CREATE FUNCTION ddf_GetLastDayOfMonth (@dtDate date)
--Highlight and execute this line to test the script
--select dbo.ddf_GetLastDayOfMonth('2/3/2015')
Returns date
AS
begin
--get the first day of the month
set @dtDate = convert(varchar(2),month(@dtDate)) + '/1/' + convert(varchar(4),year(@dtDate))
--add a month
set @dtDate = dateadd(month,1,@dtdate)
--subtract a day
set @dtDate = dateadd(day,-1,@dtdate)
return @dtDate
end
go