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

How to create an array of dates for x weeks

Featured Replies

  • Newbies

I am trying to create an array of dates that are a week apart and list for x weeks. So if a starting date is 4/25/2010, and x = 4, I would end up with:

4/25/2010

5/2/2010

5/9/2010

5/16/2010

Struggling with how to do this.. any insights would be most welcome.. TIA

Hi there! Welcome to FM Forums! :laugh2:

You can use a global field (call it gStartDate) to input the start date. You would use another global field (call it gNumWeeks) to input the number of records (weeks). Then script could be:

Loop

Exit Loop If [ $num > gNumWeeks ]

New Record/Request

Set Field [ yourDateField ; gStartDate + $num * 7 ]

Set Variable [ $num ; $num + 1 ]

End Loop

... as always, back up before trying something new in your file.

A repeating calculation field could be handy here - depending on what you need this for.

  • Author
  • Newbies

I'm using this for the left side of a relationship. So, while I could script the process, that seems to carry a lot of overhead. A calculation seems more in line with what I want to do. Any thoughts on how to structure a calculation to do this?

Then if you don't need new records, it doesn't have to be scripted.

Let (

i = Get ( CalculationRepetitionNumber ) ;

Extend ( gStartDate ) + 7 * i

)

Try:


Let ( [

i = Get ( CalculationRepetitionNumber )

] ;

Case ( i ≤ Extend ( x ) ; Extend ( StartDate ) + 7 * ( i - 1 ) )

)

Give the field enough repetitions to cover the worst case scenario.

I was just going to modify so it stopped according to a specified number of weeks. And I was also going to add that I got this calculation originally from you. In fact, it's on my wall because it's so pretty. :wink2:

That's nice - usually they tell me I'm off the wall, not on it.

  • Author
  • Newbies

Can you explain how I should implement this a little more. I created a calculation field with 16 repetitions which references a startdate field, but it does not give me the result I need. I also noticed that where you have:

i ≤ Extend ( x )

If I try to use a number rather than x, FileMaker tells me that I need to reference a field rather than use an expression.

"but it does not give me the result I need. "

What result does it give you? Did you go to field setup and change so the calc displays the repetitions? If the calc produces a series of numbers (similar to 73387) then the result of the calculation must be changed to date.

You should replace the x with a global field which holds the number of weekly dates you specify (such as 4). It could also be an unstored number calculation (with only the number 4 in it) but you would have to amend the calc every time you wanted to change the number.

Edited by Guest

If x is a constant rather than a variable, then you can shorten the formula to =

Extend ( StartDate ) + 7 * ( Get ( CalculationRepetitionNumber ) - 1 )

and make the number of repetitions equal to x.

Create an account or sign in to comment

Important Information

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

Account

Navigation

Search

Search

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.