PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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:
/// 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:
The array is dumping correct Monday dates
BUT, those dates are between today's date and the $finish date.
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?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
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?