Date functions – last day of month

/********************************************
Example:
select [dbo].[LastDayOfMonth]('01/30/2006')
select [dbo].[LastDayOfMonth]('07/30/2009')
*********************************************/
CREATE FUNCTION [dbo].[LastDayOfMonth] ( @Date DATETIME )
RETURNS DATETIME
AS BEGIN

    DECLARE @DatePlusMonth DATETIME
    SET @DatePlusMonth = DATEADD(m, 1, @Date)

    RETURN DATEADD(d, ( -) * DAY(@DatePlusMonth), @DatePlusMonth) 

   END

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s