I’ve got the following function which I had help building at this topic
function nextDelivery($day,$o_date,$oc) {
$day_names = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
$day_num = array_search($day, $day_names);
$o_date = new DateTime($o_date);
$o_day_num = $o_date->format('w');
$day_diff = ($day_num - $o_day_num) % 7;
if($day_diff<0){$day_diff=7+$day_diff;}elseif($day_diff==0){$day_diff=7;}
if($oc==2){$day_diff+7;}
$order_day = clone $o_date;
$order_day->add(new DateInterval("P".$day_diff."D"));
return $order_day->format('Y-m-d H:i:s');
}
Now I’ve just changed my time stamp to Pacific/Auckland, as my host was America/Denver. This has changed everything except for files run using Cron Jobs, they are still outputting the old timestamp. Now if I run this function on a page in my site it woks fine, but if a cron job file, using the exact same function runs I get the following error
PHP Fatal error: Call to undefined method DateTime::add() in ***** on line 156
which is $order_day->add(new DateInterval("P".$day_diff."D"));
This is my info http://www.dpdesignz.co.nz/homefresh/lib/php_info.php
Does anyone have any ideas as to why this may be happening?
DateTime::addwas added in PHP 5.3.0. Your cron job is probably using an older version. Try to upgrade, or change the version it uses. If you can’t do that, then, as mentioned in the notes:DateTime::modifyis an alternative.