arof
asked on
SQL SERVER & Date function
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks all..
create function dbo.ReturnLastDayOfPrevMon
returns datetime
as
begin
return dateadd(d, -1, convert(datetime, left(@theDate, 6) +'01', 112))
end
go
select dbo.ReturnLastDayOfPrevMon