Posted by: R Manimaran | February 14, 2007

No. of days in a Month in Sql server

CREATE FUNCTION [dbo].[ufn_GetDaysInMonth] ( @pDate    DATETIME )
 RETURNS INT AS
  BEGIN
      RETURN CASE WHEN MONTH(@pDate) IN (1, 3, 5, 7, 8, 10, 12) THEN 31
                  WHEN MONTH(@pDate) IN (4, 6, 9, 11) THEN 30
        ELSE CASE WHEN (YEAR(@pDate) % 4    = 0 AND YEAR(@pDate) % 100 != 0) OR (YEAR(@pDate) % 400  = 0) THEN 29
        ELSE 28
END
END
END
GO
Advertisements

Responses

  1. No. of days in a Month in Sql server
    ~~~~~~~~~~~~~~~~~~~~~~~~

    Ya.. I seen this… It’s good . useful one


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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Categories

%d bloggers like this: