I'm programming something that calculates new dates on a given interval type and interval multiplier. Similar to the Palm Pilot's calendar functions, you can say "every 3rd Week on a Sunday" or "every 3 months on the 2nd tuesday" and so on. The code below was what i wrote thinking that the mktime function ought to handle the recalculation of odd dates (the 54th day of a month, calculating it as a day in the next month) as the php documentation seems to suggest it would.
$month = substr($order["Shipping_Request_Date"],5,2);
$day = substr($order["Shipping_Request_Date"],8,2);
$year = substr($order["Shipping_Request_Date"],0,4);
switch($row['Repeat_Interval_Type'])
{
case 'WEEK':
$day += ($order['Repeat_Interval_Multiplier'] 7);
break;
case 'MONTH_BY_DAY':
$old = date( 'w', mktime(0,0,0,$month,$day,$year));
$new = date( 'w', mktime(0,0,0,$month + $order['Repeat_Interval_Multiplier'],$day,$year));
$modifier = (floor($day/7) - floor(($day+($old-$new))/7)) 7;
$month += $order['Repeat_Interval_Multiplier'];
$day += $modifier;
break;
case 'MONTH_BY_DATE':
$month += $order['Repeat_Interval_Multiplier'];
break;
case 'YEAR':
$year += $order['Repeat_Interval_Multiplier'];
break;
}
$new_ship_date = date( 'Y-m-d', mktime(0,0,0,$month,$day,$year));
however this is not working as expected. I am getting very odd dates. any ideas as to what's wrong/ a possible fix or different implementation?