Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Senior Member tha_Gsheep's Avatar
    Join Date
    Feb 2003
    Location
    Scotland
    Posts
    188
    Member #
    780
    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
    www.appletv.co.uk

  2.  

  3. #2
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Out of curiosity, why are you working this all in timestamp-land and not doing it in basis to the day of the year? That way, you would have to deal with one contingency (the 365-0 changeover) and you'd be able to do calculations in a reference frame that makes a lot more sense for your purposes.

  4. #3
    Senior Member tha_Gsheep's Avatar
    Join Date
    Feb 2003
    Location
    Scotland
    Posts
    188
    Member #
    780
    I went with the timestamps for accuracy to ensure that even across timezones the solution could be deployed the same. But I may switch. Got to leave this one to breathe a while I think.
    www.appletv.co.uk


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:12 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com