Now I see what you are after.
alter function dbo.Fn_get_last_day (@FN_InputDt datetime)
returns int
as
begin
return case when @FN_InputDt=0 then 0 else day(dateadd(m, 1+datediff(m, 0, @FN_InputDt), 0)-1) end
end
X = datediff(m, 0, @FN_InputDt) -- calculates how many months have elapsed from "virtual date 0"
Y = dateadd(m, 1+X, 0) -- adds 1+X months to the "virtual date 0", so we are in the next month (X+1)
Note: the side effect is that it also set the day-in-month to 1st day of month
Z = Y-1 -- take one day off, so we're back in this month, at the last day
Day(Z) --- get the day of month