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
What the difference between UNION and UNIONALL?
What command is used to rename the database?
Do you know hot add cpu in sql server 2008?
Can we use trigger new in before insert?
What are the differences between ms sql server & oracle?
What is difference between unique and primary key?
Write query to return all rows sql?
What are the types of lock supported by ?
How to create a trigger for insert only?
Can a trigger be created on a view?
What are diverse clauses that form a part of sql?
System variable and temporary variables
Are resultset updatable?
How optimize sql query with multiple joins in sql server?
How to run sql server 2005 books online on your local system?