I am trying to handle groups which meet either once a week, twice a month or once a month – on any day of the week. I would like to calculate the number of occurrences any given configuration would generate for a given time frame.
For example, say a group meets every Friday, from Jan 1 to June 30, how many times would they meet? Or, if a group meets on Tuesday every other week, from Jan 1 to June 30, how many times would they meet? Etc.
Is this possible in php? I’m not seeing a solution in the DateInterval manual.
Thank you for any help.
Well, first of all, you know that if there are N days between two dates, there are at least floor(N/7) of each day of the week. But it may be one more than that.
From Jan 1 to June 30 of this year (2012), for instance, is 182 days (assuming both endpoints are included). That’s exactly 26 weeks, so there are exactly 26 of each day of the week.
From Jan 1 to June 30 of next year, however, is only 181 days, or 25 weeks plus 6 days. It also happens to be 26 Fridays, but only 25 Mondays.
I recommend @philmccull’s answer from the ‘possible duplicate’ link above.