Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

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


This topic is 6654 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

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

Posted

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.

Posted

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.

Posted

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 )

);

""

)

)

Posted

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!

This topic is 6654 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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