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?

Answers were Sorted based on User's Feedback



How to get number of days in a given year?..

Answer / akshay wadkar

DECLARE @year AS INT
SET @year=2010
Select DATEDIFF(DAY,DATEADD(YEAR,@year-1900,0)
,DATEADD(YEAR,@year-1900+1,0)) AS [TOTAL NO OF DAYS]
GO

Is This Answer Correct ?    1 Yes 0 No

How to get number of days in a given year?..

Answer / 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

How to get number of days in a given year?..

Answer / rajkumar

DECLARE @IsLeapYear        BIT




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




    select 365 + @IsLeapYear

Is This Answer Correct ?    0 Yes 0 No

How to get number of days in a given year?..

Answer / satya

create function abc(@lpyr int)
returns int
As

returns 365+@udflpyr (@lpyr)

....
User Defined function is declared to find a leap yr

Is This Answer Correct ?    0 Yes 5 No

Post New Answer

More SQL Server Interview Questions

Suppose you want to implement the following relationships while designing tables. How would you do it?a.) One-to-oneb.) One-to-manyc.) Many-to-many

0 Answers  


What is meant by Active-Passive and Active-Active clustering setup?

0 Answers  


can primery key be a non clustered index?

10 Answers  


How to write the storeprocedure with in the store procedure? and how can we write the store procedure with in a trigger vice versa? plz post me the exact answer?

0 Answers   ABC,


one of my database size is 2gb and Unrestricted Growth for Data file up to 10%.But every day after day I am getting Primary Data file is full 99.999 please take appropriate actions.Why it is? Even disk space is also not full,but still I am getting the alerts.

1 Answers   Cognizant,


How do I find the port number for sql server?

0 Answers  


How to connect PK and FK?

2 Answers  


Explain the usage of floor function in sql server.

0 Answers  


How to select nth record from a table?

13 Answers   DELL, Microsoft, Ramco,


What do you mean by sql server agent?

0 Answers  


What is a join in sql? What are the types of joins?

0 Answers  


Explain the creation and execution of a user-defined function in the sql server?

0 Answers  


Categories