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.

Featured Replies

Hi there,

 

I am trying to build a calculation that formats up to 6 course dates as a single block of text.

 

For a one day course the format would be something like Mon, 23 June

For a two day course the format would be something like Mon-Tues, 23-24 June

and so on

 

The dates are not always consecutive so for instance a group of four dates might look like this:

 

Mon-Tues 23-24 June and Thur-Fri 26-27 June.

 

So there is an "and" separating the 2 blocks of 2 days. 

 

A six day course could have 5 blocks e.g. 2 dates together followed by 4 separate dates.

 

There are at least 50 possible formatting combinations for 6 or less dates.

 

I don't want to have to build a 50 clause case statement for this if theres an easier way to do it.

 

 

You could loop through a list of the course dates looking for runs of consecutive dates (where $date[$i] - 1 = $date[$i-1]) (alternately, you could think about it as looking for breaks in the consecutive runs where $date[$i] - 1 > $date[$i-1]), group those runs into blocks of the format from your two-day example, and separate the groups with "and".

See if you can adapt this to your needs:

http://www.briandunning.com/cf/734

 

Note that your case might be easier, if you consider 2 consecutive dates to be a "block" (the function above requires 3 or more). Perhaps much easier, if your block is never longer than 2 consecutive dates (as in all your examples).

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.