If you need calculate the fisrt or the last day date of a given date this stored procedure can help you
Description: returns the first or last day date
of the month
@d // the date ; if null is the current date
@FL first or last date day of the month
for 1 is the first day otherwise the last
testing:
DECLARE @R AS DATETIME
EXECUTE dbo.Usp_FirstLastMonthDayDate @R=@R,@FL=2, @D='20000223'
returns:
2000-02-29 00:00:00.000
-- with default values
DECLARE @R AS DATETIME
EXECUTE dbo.Usp_FirstLastMonthDayDate @R=@R
returns:
2009-11-01 23:10:37.393