SQL Server YEARFRAC Function
Updated 2023-10-07 00:02:08.530000
Description
Use the scalar function YEARFRAC to calculate the fraction of the year represented by the number of whole days between two dates.
Syntax
SELECT [westclintech].[wct].[YEARFRAC] (
<@Start_date, datetime,>
,<@End_date, datetime,>
,<@Basis, nvarchar(4000),>)
Arguments
@Start_date
the start date for the calculation. @Start_date is an expression that returns a datetime or smalldatetime value, or a character string in date format.
@End_date
the end date of the security. @End_date is an expression that returns a datetime or smalldatetime value, or a character string in date format.
@Basis
Is the type of day count to use. @Basis is an expression of the character string data type category.
| @Basis | Day count basis |
|---|---|
| 0 or omitted | US (NASD) 30/360 |
| 1 | Actual/Actual |
| 2 | Actual/360 |
| 3 | Actual/365 |
| 4 | European 30/360 |
| 21 | Actual/ISDA |
Return Type
float
Remarks
If the @Basis is not 0, 1, 2, 3, 4 or 21, YEARFRAC returns an error.
Examples
Select wct.YEARFRAC('02/29/2008', '03/31/2008', 0);
Here is the result set.
| column 1 |
|---|
| 0.0861111111111111 |
See Also
BUSDAYS - Calculate the number of business days between two dates
BUSINESSDATE - Calculate a Business Date from an offset
BUSINESSDATEWE - Calculate a Business Date from an offset and specified weekend days
FIRSTWEEKDAY - Calculate the last occurrence of a weekday in a given month
LASTWEEKDAY - Calculate the first occurrence of a weekday in a given month
NETWORKDAYS - Calculate the number of working days between two dates (inclusive)