I am trying to calculate the total number of events that will occur based on the following known parameters
- the date of the beginning
- expiration date
- Days of the week
- frequency of weeks (every week, every 2 weeks, etc.).
For example, based on the following example data:
- 01/05/2017
- 05/31/2017
- 1.4 (Sunday, Wednesday)
- Every 2 weeks
I would have to calculate that this event would work four times (5/7, 5/10, 5/21, 5/24)
Below is the skeleton. I am completely obsessed with how to increase the current day in a cycle based on the number of weeks.
<cfset local.totalRuns = 0 />
<cfset local.startDate = '2017-05-01' />
<cfset local.endDate = '2017-05-31' />
<cfset local.totalDays = DateDiff("d", local.startDate, local.endDate) />
<cfset local.daysPerWeek = '1,4' />
<cfset local.recurrence = 2 />
<cfset local.currentLoop = 0 />
<cfset local.weeksToCount = local.recurrence * 2 />
<cfloop from="#local.startDate#" to="#local.endDate#" index="local.thisDay" step="#createTimespan(1, 0, 0, 0)#">
<cfset local.currentDate = local.thisDay />
<cfloop list="#local.daysPerWeek#" index="local.currentDay">
<cfif DateDiff("d", local.currentDate, local.endDate) LTE 0>
<cfset local.totalRuns++ />
</cfif>
</cfloop>
<cfset local.currentLoop++ />
</cfloop>
source
share