ddf_GetLastDayOfMonth

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

RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences