Page 1 of 1

Getting Close - but need Help

Posted: Wed Sep 04, 2013 8:46 am
by Pavilion
Hello Everyone:

I think I'm getting close, but need a little assist to get over the hump. In short, I'm trying to generate monday dates between a begin date and an end date. Following is my test script:

Code: Select all

/// add by weeks
$start = strtotime("09/12/2013 07:00 PM");
$end = strtotime("09/12/2013 09:00 PM");
$finishCycle = strtotime("10/01/2014 07:00 PM");

$repeatStart = date("h:i:s", strtotime(date("h:i:s", $start))); 
$repeatEnd = date("h:i:s", strtotime(date("h:i:s", $end)));
$subArry = Array();
$repeatArry = Array();
$finish = date("m/d/Y", $finishCycle);
$return = date("m/d/Y", $start);
$iterate = 0;
// while compares finish date to date returned from function. If the return date is >= finish then the while continues to loop
while(strtotime($finish)>=strtotime($return))
  {
  $return = date("m/d/Y", strtotime(' Monday +'.$iterate.' week')) ; 
  $returnStart = $return . " " . $repeatStart;
  $iterate = $iterate + 1;
	  if (strtotime($return)<=strtotime($finish))
	  {
	 //  echo "return: " . date("D m/d/Y h:i:s", strtotime($returnStart)) . "</br>";

			$subArry = array();
			$mondayStart = date("D m/d/Y h:i:s", strtotime($returnStart)); 
			// $mondayEnd  = date("Y-m-d", strtotime(' Monday +'.$i.' week')) . " " . $repeatEnd; 
			array_push($subArry, $mondayStart);
			array_push($repeatArry, $subArry);  
	  } 
  } 
var_dump($repeatArry);
At this point I'm holding off on generating $mondayEnd until I can figure out how to get $mondayStart correct output. My problem is as follows:
  1. The array is dumping correct Monday dates
  2. BUT, those dates are between today's date and the $finish date.
  3. How do I get this line: $return = date("m/d/Y", strtotime(' Monday +'.$iterate.' week')) ; to start iterating off of the actual start date ($start)instead of today's date?
Thanks in advance for your assistance. ~ Pavilion

Re: Getting Close - but need Help

Posted: Wed Sep 04, 2013 10:21 am
by AbraCadaver
Not sure what your doing with the times, but here's a simpler start maybe:

Code: Select all

for($next=strtotime('Monday', $start); $next <= $finishCycle; $next=strtotime('next Monday', $next)) {
    $array[] = date('"D m/d/Y h:i:s', $next);
}
print_r($array);

Re: Getting Close - but need Help

Posted: Wed Sep 04, 2013 4:53 pm
by Pavilion
AbraCadaver wrote:Not sure what your doing with the times, but here's a simpler start maybe:

Code: Select all

for($next=strtotime('Monday', $start); $next <= $finishCycle; $next=strtotime('next Monday', $next)) {
    $array[] = date('"D m/d/Y h:i:s', $next);
}
print_r($array);
Thank you so much AbraCadaver. You're help is appreciated. ~ Pavilion

Re: Getting Close - but need Help

Posted: Wed Sep 11, 2013 2:02 pm
by Pavilion
AbraCadaver wrote:Not sure what your doing with the times, but here's a simpler start maybe:

Code: Select all

for($next=strtotime('Monday', $start); $next <= $finishCycle; $next=strtotime('next Monday', $next)) {
    $array[] = date('"D m/d/Y h:i:s', $next);
}
print_r($array);
I'm back :) with a new twist.

You wondered what I was going to do with the times. My users want to be able to setup repeat events in their scheduling application. They really like the new ability to generate activities on the same day of the week every week, 2 weeks, etc... However, they are now asking for the ability to generate repeat events on the same day/week every month or the same day/week of the same month every year. An example might be the 1st Tuesday of every month, or the 2nd Wednesday in January every single year.

Do you have any suggestions at all on how to generate the same week & day every month, or the same month, week and day every year?

Thanks in Advance - Pavilion