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
Do you know sql server 2008 backup compression?
What does man by sql wildcard characters in sql server?
What are different types of subquery?
Explain different backup plans?
What is sql injection? How to protect against sql injection attack?
Is there any difference between the primary key and unique key?
Can we take the full database backup in log shipping?
Explain the third normal form(3nf)?
Do you know how to store and query spatial data?
Why use stored procedures in sql server?
What is cached report?
What is the server name for sql management studio?
How to transfer an existing table from one schema to another schema in ms sql server?
What is the difference between sql server 2000 object owner and sql server 2005 schema? : sql server database administration
Explain partitioned view?