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 what is a trace frag? Where do we use it?
What is merge statement?
How to find the service pack installed? : sql server database administration
Why we use the openxml clause?
What is normalization 1nf 2nf 3nf?
Can multiple columns be used in sql group by clause in ms sql server?
Your sql server is running out of disk space. You notice that there are several large files with ldf extensions what are these files?
What is scalar user-defined function?
Is it possible to run multiple publications and different type of publications from the same distribution database? : sql server replication
What is Extended user-defined?
How to create sub reports?
What is postgresql server?
Does an index slow down updates on indexed columns?
Explain what are partitioned views and distributed partitioned views?
How does the report manager work in SSRS?