Technical Article

Last_Date_Of_Month

,

Get the Last date of the month for the given month and year

CREATE PROCEDURE [dbo].[sp_Last_Date_Of_Month]
 @M int, @Y int
AS
DECLARE @I int
DECLARE @dt varchar(10)
SET @I = 0

Set @dt = CONVERT(char(2), @M) + '/' +'01/' +  CONVERT(char(4), @Y) 
Select @I = @I  + 1

WHILE MONTH(DateAdd(day,@I,@dt)) = @M
 BEGIN
  Select @I = @I  + 1
END

Select Day( DATEADD(day,@I-1, @dt))
GO

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating