Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How to get number of days in a given year?

Answer Posted / anamika devara

Getting the number of days in a year is fairly easy because you are just choosing between 365 and 366, with the latter only happening every 4 years or every leap year.  To determine if it is a leap year, either of the following conditions must be met:




The year must be divisible by 4 and must NOT be divisible by 100.
The year must be divisible by 400.
Below is a user-defined function which accepts a date as a parameter and returns the number of days in that year.





CREATE FUNCTION [dbo].[ufn_GetDaysInYear] ( @pDate    DATETIME )
RETURNS INT
AS
BEGIN




    DECLARE @IsLeapYear        BIT




    SET @IsLeapYear = 0
    IF (YEAR( @pDate ) % 4 = 0 AND YEAR( @pDate ) % 100 != 0) OR
        YEAR( @pDate ) % 400 = 0
        SET @IsLeapYear = 1




    RETURN 365 + @IsLeapYear




END
GO

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a Join and explain its types?

1103


How to stop a loop early with break statements in ms sql server?

1020


What is the optimization being performed in oracle and SQL Server?

1051


Can we shrink data file in sql server?

1053


What is the purpose of the tempdb database?

1000


Why functions are used in sql server?

964


What are triggers? How do you invoke a trigger on demand?

1318


What is sql stored procedure?

1099


How to execute multiple stored procedures at one time in sql server?

1014


What is local temp table?

965


What the different topologies in which replication can be configured?

1092


What are the different types of columns types constraints in the sql server?

1080


Name the different type of indexes in sql?

965


What is openrowset sql server?

1135


how can a database be repaired? : Sql server administration

978