I have a calendar and I'm adding recurring events to it, My problem is that the user can set a "repeat for x amount of months" variable, this variable is my $repeat_value and if it exceeds 12 i need to handle it in a way that the date year increases by 1, and i should set the month to 1, then add remaining months... how can i do this?
my code is setup like this:
for ($i = 1; $i < $repeat_value; $i++)
{
if ($repeat_type == "month")
{
if ($i > 12) //month is greater then 12, we must increase the year +1 and set month to jan
{
//please help!
}
else
{
$t_temp_start = date('Y-m-d h:m:s',strtotime($s_start . '+ ' . $i . ' months'));
$t_temp_end = date('Y-m-d h:m:s',strtotime($s_end . '+ ' . $i . ' months'));
}
$database->justquery("INSERT INTO tbl_events (`title`, `start`, `end`, `url`) VALUES ('" . $event_name . "', '" . $t_temp_start . "', '" . $t_temp_end . "', '" . $url . "');");
}
else if ($repeat_type == "year")
{
$t_temp_start = date('Y-m-d h:m:s',strtotime($s_start . '+ ' . $i . ' years'));
$t_temp_end = date('Y-m-d h:m:s',strtotime($s_end . '+ ' . $i . ' years'));
$database->justquery("INSERT INTO tbl_events (`title`, `start`, `end`, `url`) VALUES ('" . $event_name . "', '" . $t_temp_start . "', '" . $t_temp_end . "', '" . $url . "');");
}
}
I hope this makes sense, help appreciated!