Technical Article

Last_Date_Of_Month

,

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

In response to a post By: Anonymous - Posted: 2/16/2004 3:31:12 AM (Stored Procedure)....

Thought that there should be a more efficient / functional way of doing this. And here it is. Of course, a function would probably be more efficient, and a datetime parameter might make the interface easier to use.

CREATE PROCEDURE [dbo].[sp_Last_Date_Of_Month]
 @m integer, @y integer
AS

declare @date datetime
set @date = cast(@y as char(4)) + '-' + 
    cast(@m as varchar(2)) + '-01'
Select day(@date + 32 - datepart(day, @date + 32))
GO

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating