http://reddymsbitools.blogspot.com

Monday, 18 October 2010

Total number of days in a month

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:
-- Create date: <25th July, 2009>
-- Description:
-- =============================================
CREATE FUNCTION [dbo].[getTotalDaysInMonth]
(
-- Add the parameters for the function here
@anydateofMonth DATETIME
)
RETURNS INT
AS
BEGIN
-- Declare the return variable here
DECLARE @totalDaysInMonth INT
-- Add the T-SQL statements to compute the return value here

DECLARE @givendate DATETIME
SET @givendate = @anydateofMonth

SET @givendate = STR(YEAR(@givendate)) + '-' + STR(MONTH(@givendate) + 1) + '-01'

SELECT @totalDaysInMonth = DATEPART(dd, DATEADD(DAY, -1, @givendate))

-- Return the result of the function
RETURN @totalDaysInMonth


SELECT dbo.getLastBusinessDay(GETDATE()) AS TotalDaysInMonth
END

No comments:

Post a Comment