I need a function that returns the last day on the previous month of given date . any idea?
example:
if date = 20070530, then, the last day of previous month is 20070430
if date = 20070630, then, the last day of previous month is 20070531
and so on..
returns: datetime
parameter: datetime
any idea?
create function dbo.ReturnLastDayOfPrevMon
returns datetime
as
begin
return dateadd(d, -1, convert(datetime, left(@theDate, 6) +'01', 112))
end
go
select dbo.ReturnLastDayOfPrevMon