Can someone help me figuring out how to get if a current week is inside an occurrence .
I have the following vars : start_date , end_date , current_date week_occurrence .
and i have a function that return the # of occurrence
// will return the number of weeks between start - end
function get_weeks_count($start , $end) {
return floor(abs(strtotime($start) - strtotime($end)) / 604800);
}
now i have to know if a current date is a valid date .
I have an entry with occurrence = every N weeks . How to know that N is valid .
Less abstract : If we are in December and the occurrence is every 3 weeks , start_date is 1st and end_date is 30 December)
It will return :
TRUE for 1st week
FALSE for the second week
FALSE for the third week
TRUE for the last week
Here’s how I would approach the problem – this applies for an occurrence every $n weeks.
If
$occurrenceis still false then the current week does not fall within the the correct occurrence, if it’s true then the week does fall within the scope.Effectively all we’re doing here is checking that the current number of weeks since the start date is either equal to zero (we’re still in the first week) or is divisible by the ocurrence without a remainder.
I hope this helps.
P.S. I’ve only answered the specific question that you asked. However, if you would like to know more about how this premiss could be used for scheduling etc., then feel free to ask and I’ll expand on my answer accordingly