September 3, 200619 yr I am trying to creat a CF to do the following given: Input: startDate = starting date for range endDate = ending date for range dateList = list of dates we would like to test count = initial value of 0 Output: count of the number of times a date from dateList falls within the range [startDate, endDate] parse each element of the list: dateList (a list of dates) to check if startDate <= currentDate <= endDate, if it is increment counter by 1 dateList is a return separated list of dates (MM/DD/YYYY). I'm familar with recursion, but can't seeem to get my head around this. I also wonder if someone else has already developed this CF. It is of course trival when dateList is a single element list. The problem I'm having is with the recursion. I stuck with how to recursively walk the dateList and keep track of tne count of how many times a date from dateList falls within the range. TIA
September 3, 200619 yr It seems simple enough: Let ( [ item = GetValue ( dateList ; counter ) ; iDate = GetAsDate ( item ) ; test = startDate ≤ iDate and iDate ≤ endDate ] ; Case ( counter ≤ ValueCount ( dateList ) ; test + ThisFunction ( startDate ; endDate ; dateList ; counter + 1 ) ) ) If your file/system is NOT set up to use MM/DD/YYYY, do a proper text parse to get the date using the Date() function. You would call this function with 1 as the initial counter value.
September 3, 200619 yr Author It seems simple enough: Let ( [ item = GetValue ( dateList ; counter ) ; iDate = GetAsDate ( item ) ; test = startDate ≤ iDate and iDate ≤ endDate ] ; Case ( counter ≤ ValueCount ( dateList ) ; test + ThisFunction ( startDate ; endDate ; dateList ; counter + 1 ) ) ) If your file/system is NOT set up to use MM/DD/YYYY, do a proper text parse to get the date using the Date() function. You would call this function with 1 as the initial counter value. I figured it had to be simple, but the counter was messing me up. Thanks very much. regards.
September 3, 200619 yr Hi this is another way to do the same thing without the fourth parameter ( and it works on FM 7 too ) cf ( dateList ; startDate ; endDate ) Let([ firstRow = GetAsDate ( LeftValues ( dateList ; 1 ) ); next = RightValues ( dateList; ValueCount ( dateList ) - 1 ) ]; Case( not IsEmpty ( firstRow ) and not IsEmpty ( startDate ) and not IsEmpty ( endDate ); Case( firstRow ≥ startDate and firstRow ≤ endDate ; 1 + cf ( next ; startDate ; endDate ); 0 + cf ( next ; startDate ; endDate ) ); "" ) )
September 4, 200619 yr Author Hi this is another way to do the same thing without the fourth parameter ( and it works on FM 7 too ) ...snip... Very cool. Thank you. Both approaches really helped. I'm still getting used to thinking recursively as I'm so used to programming in other languages with loop constucts. cheers!
Create an account or sign in to comment