View Thread
 Print Thread
Function to get the last date of the month for a given date
admin
Function to get the last date of the month for a given date


SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [dbo].[udf_GetLastDayOfMonth] ( @pInputDate DATETIME )
RETURNS DATETIME
    BEGIN

        DECLARE @vOutputDate DATETIME

        SET @vOutputDate = CAST(YEAR(@pInputDate) AS VARCHAR(4)) + '/' + CAST(MONTH(@pInputDate) AS VARCHAR(2)) + '/01'
        SET @vOutputDate = DATEADD(DD, -1, DATEADD(M, 1, @vOutputDate))

        RETURN @vOutputDate

    END

GO

Jordon Pilling | Heavencore Administrator
 
Jump to Forum