<-- Previous || Up || Next -->

Year Fraction Test Sub
Dates Times Class

Public Sub YearFractionTest()
    'Compare the YearFraction function to the Excel's YEARFRAC function.

    Const datBeg = #1/1/1991#
    Const datEnd = #1/1/1998#

    Dim datFm As Date, datTo As Date, intBasis%, dblXL#, dblES#

    For datFm = datBeg To datEnd
        DoEvents
        If Day(datFm) = 5 Then datFm = datFm + 20
        If Month(datFm) Mod 3 = 1 _
        And Day(datFm) = 1 Then Debug.Print Now, datFm

        For datTo = datBeg To datEnd
            If Day(datTo) = 5 Then datTo = datTo + 20

            For intBasis = 0 To 4
                dblXL = YearFrac(datFm, datTo, intBasis)
                dblES = YearFraction(datFm, datTo, intBasis)

                If dblXL <> dblES Then
                    If intBasis = US_NASD_30_360 Then
                        Debug.Print _
                              datFm _
                            , datTo _
                            , intBasis _
                            , dblXL _
                            & ", " & dblES _
                            & ", " & dblXL * 360 _
                            & ", " & dblES * 360
                    Else
                        Debug.Print _
                              datFm _
                            , datTo _
                            , intBasis _
                            , dblXL _
                            & ", " & dblES _
                            & ", " & 1 / dblXL * (datTo - datFm) _
                            & ", " & 1 / dblES * (datTo - datFm)
                    End If
                End If
            Next intBasis
        Next datTo
    Next datFm
End Sub

Copyright 1996-1999 Entisoft
Entisoft Tools is a trademark of Entisoft.