Trying to figure out a way of achieving the following scenario:-
The user creates an initial time period eg 01/01/2013 to 01/07/2013 and a renewal period eg every 1 month.
I'm working on a function that will:-
For example:-
The function may accept the following date 21/02/2019. Based on this I need to detect which renewal period the user is in.
The way I was thinking of achieving this is by:-
A bit confusing but this kind of sums up what I'm after but isn't working:-
$tmpStartDate=$endDate;
do{
$tmpStartDate=date("Ymd",strtotime($tmpStartDate .'+1 Day'));
$tmpEndDate=date("Ymd",strtotime($tmpStartDate .'+'.$timingUnitVal .' '.$timingUnit));
} while($date<$tmpStartDate&&$date>$tmpEndDate);
$endDate is the end date initially entered by the user.
From what I can gather from your question, something roughly along these lines would be more correct?
function findPeriod($lowerBound, $upperBound, $repeatEvery, $date)
{
$lowerBound = strtotime($lowerBound);
$upperBound = strtotime($upperBound);
$repeatEvery = strtotime('+' . $repeatEvery) - time();
$date = strtotime($date);
while ($date >= $lowerBound) {
if ($date <= $upperBound) {
return array($lowerBound, $upperBound);
} else {
$lowerBound += $repeatEvery;
$upperBound += $repeatEvery;
}
}
return false;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.