Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

CF to run through a list of dates and count number of time in specified range.

Featured Replies

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

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.

  • 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.

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 )

);

""

)

)

  • 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

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.