brainonastick Posted June 23, 2014 Share Posted June 23, 2014 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 More sharing options...
jbante Posted June 23, 2014 Share Posted June 23, 2014 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 More sharing options...
comment Posted June 23, 2014 Share Posted June 23, 2014 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). 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now