Logo

SQL Server DAYS360 Function

Updated 2023-10-06 23:45:24.680000

Description

Use the scalar function DAYS360 to calculate the number of days from a start date (inclusive) to an end date (exclusive) using any of several 30/360 day count conventions.

Syntax

SELECT [westclintech].[wct].[DAYS360] (
  <@StartDate, datetime,>
 ,<@EndDate, datetime,>
 ,<@method, int,>)

Arguments

@StartDate

the start date for the calculation. @StartDate is an expression of type datetime or of a type that can be implicitly converted to datetime.

@EndDate

the end date for the calculation. @EndDate is an expression of type datetime or of a type that can be implicitly converted to datetime.

@method

A numeric identifier indicating which 30/360 day count convention to use. Use 0 for the US method (also known as 30/360 US), 1 for the Special German method (also known as 30E/360, 30/360 ICMA, and Eurobond basis), or 2 for the German method (also known as 30E360 ISDA). @method is an expression of type int or of a type that can be implicitly converted to int.

Return Type

int

Remarks

If @method < 0 or @method > 2 an error message is generated.

If @method is NULL, then @method = 0.

@StartDate cannot be NULL.

@EndDate cannot be NULL.

Examples

This example shows the three different calculation methods for a variety of date combinations as well as showing the actual number of days between the start date and the end date.

SELECT *,
       wct.DAYS360([Start Date], [End Date], 0) as [30/360 US],
       wct.DAYS360([Start Date], [End Date], 1) as [30E/360],
       wct.DAYS360([Start Date], [End Date], 2) as [30E360 ISDA],
       DATEDIFF(d, [Start Date], [End Date]) as Actual
FROM
(
    SELECT '2007-01-15',
           '2007-01-30'
    UNION ALL
    SELECT '2007-01-15',
           '2007-02-15'
    UNION ALL
    SELECT '2007-01-15',
           '2007-07-15'
    UNION ALL
    SELECT '2007-09-30',
           '2008-03-31'
    UNION ALL
    SELECT '2007-09-30',
           '2007-10-31'
    UNION ALL
    SELECT '2007-09-30',
           '2008-09-30'
    UNION ALL
    SELECT '2007-01-15',
           '2007-01-31'
    UNION ALL
    SELECT '2007-01-31',
           '2007-02-28'
    UNION ALL
    SELECT '2007-02-28',
           '2007-03-31'
    UNION ALL
    SELECT '2006-08-31',
           '2007-02-28'
    UNION ALL
    SELECT '2007-02-28',
           '2007-08-31'
    UNION ALL
    SELECT '2007-02-14',
           '2007-02-28'
    UNION ALL
    SELECT '2007-02-26',
           '2008-02-29'
    UNION ALL
    SELECT '2008-02-29',
           '2009-02-28'
    UNION ALL
    SELECT '2008-02-29',
           '2008-03-30'
    UNION ALL
    SELECT '2008-02-29',
           '2008-03-31'
    UNION ALL
    SELECT '2007-02-28',
           '2007-03-05'
    UNION ALL
    SELECT '2007-10-31',
           '2007-11-28'
    UNION ALL
    SELECT '2007-08-31',
           '2008-02-29'
    UNION ALL
    SELECT '2008-02-29',
           '2008-08-31'
    UNION ALL
    SELECT '2008-08-31',
           '2009-02-28'
    UNION ALL
    SELECT '2009-02-28',
           '2009-08-31'
) n([Start Date], [End Date]);

This produces the following result.

Start DateEnd Date30/360 US30E/36030E360 ISDAActual
2007-01-152007-01-3015151515
2007-01-152007-02-1530303031
2007-01-152007-07-15180180180181
2007-09-302008-03-31180180180183
2007-09-302007-10-3130303031
2007-09-302008-09-30360360360366
2007-01-152007-01-3116151516
2007-01-312007-02-2828283028
2007-02-282007-03-3130323031
2006-08-312007-02-28178178180181
2007-02-282007-08-31180182180184
2007-02-142007-02-2814141614
2007-02-262008-02-29363363364368
2008-02-292009-02-28360359360365
2008-02-292008-03-3030313030
2008-02-292008-03-3130313031
2007-02-282007-03-055755
2007-10-312007-11-2828282828
2007-08-312008-02-29179179180182
2008-02-292008-08-31180181180184
2008-08-312009-02-28178178180181
2009-02-282009-08-31180182180184