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
How to get a list of columns in a view using the "sp_help" stored procedure?
Can sql servers linked to other servers like oracle?
What is data modeling and Reterminal integrity?
What is the difference between char, varchar and nvarchar?
Is sql server a database?
What is #temp and @table variable in SQL server?
Explain syntax for dropping triggers?
Working with TLogs
How many database files are there in sql server 2000?what are they?
What is the server name in sql server?
What is the sql case statement used for?
What the class forname () does?
What is sql server replication? : sql server replication
Explain the microsoft sql server delete command? : SQL Server Architecture
How to enter comments in transact-sql statements?