YEARFRAC
Updated 2023-10-07 00:02:08.530000
Syntax
SELECT [westclintech].[wct].[YEARFRAC] (
<@Start_date, datetime,>
,<@End_date, datetime,>
,<@Basis, nvarchar(4000),>)
Description
Use the scalar function YEARFRAC to calculate the fraction of the year represented by the number of whole days between two dates.
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.
{"columns":[{"field":"@Basis","width":139},{"field":"Day count basis","width":174}],"rows":[{"@Basis":"0 or omitted","Day count basis":"US (NASD) 30/360"},{"@Basis":"1","Day count basis":"Actual/Actual"},{"@Basis":"2","Day count basis":"Actual/360"},{"@Basis":"3","Day count basis":"Actual/365"},{"@Basis":"4","Day count basis":"European 30/360"},{"@Basis":"21","Day count basis":"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.
{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"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)