How to get number of days in a given year?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
What are the pros and cons of putting a scalar function in a queries select list or in the where clause?
When a primary key constraint is included in a table, what other constraints does this imply?
How to drop existing indexes in ms sql server?
Explain different types of Normalization.
1 Answers HPCL, Hughes Systique Corporation, Ittiam Systems,
What is the command used to recompile the stored procedure at run time?
you notice that the transaction log on one of your databases is over 4gb the size of the data file is 2mb what could cause this situation, and how can you fix it? : Sql server administration
What is relationship? What number of sorts of relationship are there?
What do you understand by the data quality services in sql server?
What is an indice?
how will u create "n" possible tables in sql...
How you can find out if an index is useful to the optimizer?
What is the difference between Triggers and Stored Procedure?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)