[AccessD] Days 360

Gustav Brock gustav at cactus.dk
Thu Jan 29 04:16:04 CST 2004


Hi Jeffrey

First, are you aware of the typo here:

> Month(myEndDate), 1)) - 1 Or Day(myendate) = 30 Then

Second, a performance as Excel's Days360() may not be the ultimate
goal as it not up to the standards. Visit this link to read more and
for data samples:

  http://www.entisoft.com/ESTools/MathFinancial_Days360.HTML

/gustav



> I have the following function that is used to calculate the number of days
> based on a 360 day year.  When I compare the results to Excel's Days360
> formula I get a different result.

> The start date I am using is 11/30/2003 and an end date of 12/31/2003

> My function returns 31 days and Excel returns 30 days.

> Can anyone see/tell me why I am getting a different result.

> TIA

> Jeff

> Function CalcDays360(mystartdate As Date, myEndDate As Date) As Double
> Dim mytotaldays

> mytotaldays = 0

> Select Case DateDiff("m", mystartdate, myEndDate)
>     Case 0 'Both dates are in the same month
>         If myEndDate <> DateAdd("m", 1, DateSerial(Year(myEndDate),
> Month(myEndDate), 1)) - 1 Then
>             mytotaldays = DateDiff("d", mystartdate, myEndDate) + 1
>         Else
>             If Day(mystartdate) <> 31 Then
>                 mytotaldays = 30 - Day(mystartdate) + 1
>             Else
>                 mytotaldays = 1
>             End If
>         End If
>     Case Else 'Dates are not in the same month
>         'Determine Number of Days in the first month
>         If Day(mystartdate) <> 31 Then
>             mytotaldays = 30 - Day(mystartdate) + 1
>         Else
>             mytotaldays = 1
>         End If

>         'Add Number of Days in the second month
>         If myEndDate = DateAdd("m", 1, DateSerial(Year(myEndDate),
> Month(myEndDate), 1)) - 1 Or Day(myendate) = 30 Then
>             mytotaldays = mytotaldays + 30
>         Else
>             mytotaldays = mytotaldays + Day(myEndDate)
>         End If

>         'Add 30 days to total number for each whole months between dates
>         mytotaldays = mytotaldays + (30 * (DateDiff("m", mystartdate,
> myEndDate) - 1))
> End Select

> CalcDays360 = mytotaldays
> End Function



More information about the AccessD mailing list