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

Do you know what is a trace frag? Where do we use it?

1040


What is merge statement?

1132


How to find the service pack installed? : sql server database administration

1062


Why we use the openxml clause?

1055


What is normalization 1nf 2nf 3nf?

1107


Can multiple columns be used in sql group by clause in ms sql server?

1114


Your sql server is running out of disk space. You notice that there are several large files with ldf extensions what are these files?

1251


What is scalar user-defined function?

1186


Is it possible to run multiple publications and different type of publications from the same distribution database? : sql server replication

1030


What is Extended user-defined?

1029


How to create sub reports?

251


What is postgresql server?

1057


Does an index slow down updates on indexed columns?

1033


Explain what are partitioned views and distributed partitioned views?

1012


How does the report manager work in SSRS?

158