DDay(StartDay,EndDay)

DDay is a function within ddGlobal and forms part of the ddDate suite of macros.  It is use to calculate the “Difference” between two dates that is in the numeric format YYYYMMDD.  It assumes there is only 360 days in a year.  If you need a higher degree of accuracy, it may be better to convert the number “YYYYMMDD” into two Excel dates and just subtract the two.  (I wrote this macro a very long time ago)

if we enter the formula

=+dday(20000101,20130306)

then that boils down to there being 4745 days since the January 1, 2000 till today whereas if one converts those two dates to proper excel dates and subtract the two, then it produces an answer of 4,813.  As mentioned, this macro was not created for accuracy but for a very specific purpose (which now eludes me)

Function DDay(StartDay As Long, EndDay As Long) As Variant
'Calculates the dif between 2 dates based on a 360 day year

If StartDay < 19000000 Or EndDay < 19000000 Then GoTo IncorrectFormat
    DDay = (((Left(EndDay, 4)) - (Left(StartDay, 4))) * 360) + (((Mid(EndDay, 5, 2)) - (Mid(StartDay, 5, 2))) * 30) + (((Right(EndDay, 2)) - (Right(StartDay, 2))) * 1)
Exit Function

IncorrectFormat:
    DDay = "Err: YYYYMMDD"
End Function

 

This entry was posted in Articles, ddGlobal, Tips and tagged , . Bookmark the permalink.



Leave a Reply