Reputation: 141
I've read that this function should work in 5.3 but not 5.2 so I am unsure why I am getting fatal errors from PHP. Sadly I am not a coder by any means, was hoping I could get some guidance. Thanks!
function date_diff($start, $end="NOW")
{
$sdate = strtotime($start);
$edate = strtotime($end);
$time = $edate - $sdate;
if($time>=86400) {
// Days + Hours + Minutes
$pday = ($edate - $sdate) / 86400;
$preday = explode('.',$pday);
$phour = $pday-$preday[0];
$prehour = explode('.',$phour*24);
$premin = ($phour*24)-$prehour[0];
$min = explode('.',$premin*60);
$presec = '0.'.$min[1];
$sec = $presec*60;
$timeshift = $preday[0];
}else{
$timeshift = 0;
}
return $timeshift;
}
Upvotes: 0
Views: 1645
Reputation: 3437
Cannot redeclare XXXX() simply means that you are trying to declare somethign that already exists.
The date_diff function has already been defined so check if it is already defined before defining it again. You can do this using function_exists()
if (!function_exists("date_diff"))
{
function date_diff($start, $end="NOW")
{
$sdate = strtotime($start);
$edate = strtotime($end);
$time = $edate - $sdate;
if($time>=86400) {
// Days + Hours + Minutes
$pday = ($edate - $sdate) / 86400;
$preday = explode('.',$pday);
$phour = $pday-$preday[0];
$prehour = explode('.',$phour*24);
$premin = ($phour*24)-$prehour[0];
$min = explode('.',$premin*60);
$presec = '0.'.$min[1];
$sec = $presec*60;
$timeshift = $preday[0];
}else{
$timeshift = 0;
}
return $timeshift;
}
}
Just to clarify, you only need to define the function like this is you want your code to work on versions of php newer AND older than 5.3 If you are only using 5.3+ then you do not need to declare this function at all as it already exists, you can just use date_diff() without defining it
Upvotes: 2