User Id :    Password :      New Member   Forgot Password  
 
Simple function to check beginning or end of month
Description Simple function to check beginning or end of month   No. of Views     705
  Rating     0
Author Akhil   Posted On     23 Oct 2011
Tags ADO.NET,SQL SERVER,SQL SERVER : How To    

Sample Code   Download Code



Simple function to check beginning or end of month

Here is the simple function that returns -1 if date passed to the function is begening of the month, 1 if its end of the month else returns 0.

 

CREATE FUNCTION dbo.fnIsOnMonthEdge
(
    @theDate DATETIME
)
RETURNS SMALLINT
AS
BEGIN
    RETURN CASE @theDate
                WHEN '99991231' THEN 1
                ELSE DATEDIFF(MONTH, @theDate, DATEADD(DAY, 1, @theDate))
            END +
            CASE @theDate
                WHEN '17530101' THEN -1
                ELSE DATEDIFF(MONTH, @theDate, DATEADD(DAY, -1, @theDate))
            END
END


Output

 

 

 

About Author

About Author Having 3.5 Years Experience in Microsoft .NET technology. Akhil
No Photo
 
Country India
Company Imfinity India Pvt. Ltd.
Home Page ma5group.co.nr

Rate this article

Rating options from poor, fair, good, very good to excelent.  
 

Comments

   
Write your comment here.
Comment
Verification Code