Dynadot โ€” .com Transfer

Find a recurring date based on its creation date

Spaceship Spaceship
Watch

tha_Gsheep

Established Member
Impact
0
Hi there! I have a tricky problem finding the number of days until a particular date using only its creation date. The only date held in the DB is its creation date and the day of the week it recurs on. The Day of the week is represented as 0-7. I use timestamps to find the exact number of seconds between the two dates (eventStartDate is a timestamp) and then divide them by 7 to find the number of weeks then I round up the result to get an even number of weeks. The function is supposed to return the number of days until the next Repeating event which I can append onto a time stamp to show the exact date.


Code:
function nextRepEvent($currentDayNo, $eventRecurDay, $eventStartDate){

	//Easier to work with "7" representing Sunday
	if ($eventRecurDay==0){
		$eventRecurDay=7;
	}			
	
	if($currentDayNo > $eventRecurDay)
	{
		if ($eventStartDate - mktime(0, 0, 0, date("m"), date("d"), date("Y")) < 1)
		{				
			//event is in the following week
			$diff = 7 - $currentDayNo + $eventRecurDay;
			
		}else{
					
			//event is more than one week in the future
			$weeksUntil = ceil( 7 / ($eventStartDate - mktime(0, 0, 0, date("m"), date("d"), date("Y"))));
			$diff = $weeksUntil*7 - $currentDayNo + $eventRecurDay;
			
		}				
	}else
	{
		//event is within the current week
		$diff = $eventRecurDay - $this->currentDayNo;
	}
	
	return $diff;
}


Any help solving or make the function more efficient would be appreciated. Thanks
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
.US domains.US domains
I think the logic is whats wrong, I'll post again when I have it sussed better.
 
0
•••
Domain Recover
DomainEasy โ€” Live Options
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back