Hi guys, I’m in search of a function that can calculate from a given date when an event would recur and then possibly return everything in an array. I’ve been trying to do this all day with no luck. Below is what I kind of already have.
function get_events($origDate, $startDate, $endDate, $recurIntval)
$events = array();
$dateDiff = $origDate - $startDate;
// Needs to be more calculations here
while ($recurDate >= $startDate && $recurDate <= $endDate)
$events = array('date' => $recurDate);
$recurDate += $recurIntval;
Assuming that all the parameters are in seconds. If anyone could help me out, I’ll greatly appreciate it.
Well let’s say for example, 25th of December is Christmas (which is 1293235200 seconds for this year), we know that that comes every year same date so if I add on 31536000 seconds (1 year) to that, I’ll get 2011’s Christmas. But I also want to constrain the events returned based on startDate and endDate (because it’s for a calendar).
$origDate = 1293235200; // 25th of December;
$recurIntval = 31536000; // 1 year
$startDate = 1291161600; // 1st of December
$endDate = 1293753600; // 31st of December
I ran into the same thing earlier this week. The DT class actually provides a couple of different methods for time comparison (add, modify and sub) and is nice because you can do simple comparisons between different objects natively ($datetime1 >= $datetime2, etc). It’s a solid class, but the fact that there’s only a String constructor bugs me.