ddInTCK is a function within ddGlobal and forms part of the ddDate suite of macros.  It is based on the famous, or infamous (depending on your point of view), SAS function called InTCK

It will basically take two dates that is in the text format YYYY-MM or the numeric format YYYYMM, and calculate the number of months in between them.  Obviously the SAS function is a lot more complex and it allows one to differentiate between the time intervals, but sadly enough, I don’t have the budget (nor had the need) to be coding all possible combinations of time yet.

The formula is straight forward, here is an example of it:


and this in turns produces an answer of 13 (months).

Function DDInTCK(StartDate As String, EndDate As String) As Integer
'This is a more simplistic function to the one used in SAS, to differentiate between two time periods
'Written by Denis Dell on 201105

Dim TmpStart As Integer
Dim TmpEnd As Integer

TmpStart = Val(Left(StartDate, 4)) * 12
TmpStart = TmpStart + Val(Right(StartDate, 2))
TmpEnd = Val(Left(EndDate, 4)) * 12
TmpEnd = TmpEnd + Val(Right(EndDate, 2))

DDInTCK = TmpEnd - TmpStart

End Function

The code is short and ugly, but again, it does what it says on the tin

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

Leave a Reply