Jump to content
Server Maintenance This Week. ×

Formatting multiple dates


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

Recommended Posts

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.

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This topic is 3595 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.