hya all i am getting the error in pic included in this post and i dont know what i could be i have found the following bit of code included below

                        <td><?php echo date_diff($lastlogin['lastlogin']);?></td>

then i have found the file where the coding for this sits see below

// Date difference function
if(! function_exists(date_diff) ) 
    function date_diff($start, $end="NOW")
            $sdate = strtotime($start);
            $edate = strtotime($end);

            $time = $edate - $sdate;
            if($time>=0 && $time<=59) {
                    // Seconds
                    $timeshift = $time.' seconds ';

            } elseif($time>=60 && $time<=3599) {
                    // Minutes + Seconds
                    $pmin = ($edate - $sdate) / 60;
                    $premin = explode('.', $pmin);

                    $presec = $pmin-$premin[0];
                    $sec = $presec*60;

                    //$timeshift = $premin[0].' min '.round($sec,0).' sec ';
                    $timeshift = $premin[0].' minutes ';

            } elseif($time>=3600 && $time<=86399) {
                    // Hours + Minutes
                    $phour = ($edate - $sdate) / 3600;
                    $prehour = explode('.',$phour);

                    $premin = $phour-$prehour[0];
                    $min = explode('.',$premin*60);

                    $presec = '0.'.$min[1];
                    $sec = $presec*60;

                    //$timeshift = $prehour[0].' hrs '.$min[0].' min '.round($sec,0).' sec ';
                    $timeshift = $prehour[0].' hours ';

            } elseif($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].' days '.$prehour[0].' hrs '.$min[0].' min '.round($sec,0).' sec ';
                    $timeshift = $preday[0].' days ';

            return $timeshift;

Can anyone tell me what i could be whats causing the error datediff.gif

3 Years
Discussion Span
Last Post by janicemurby

if(! function_exists(date_diff) )

Basically, your date_diff function gets defined only if it doesn't yet exist. That way you'll ensure the presence of a date_diff function across different (older) PHP versions.

However, as you may have guessed, date_diff already exists within PHP since version 5.3 and probably does as well in your environment. As you can see, the existing date_diff requires at least two parameters. Your own implementation requires one (i.e. it's not solving the problem it's intended to solve, namely that of implementing a potentially missing date_diff function yourself).

If date_diff does not exist in a certain environment your version will be used and your call would be correct (with one parameter). However, if it does exist your implementation will not be used and your call is incorrect since the original function needs two parameters.


i brought the script with it already like this so how can i solve this as the person i brought it from isnt answering any questions now so im left with sorting it myself


If you know the environment you will be using has PHP 5.3 or greater you can leave out that custom implementation altogether.

Assuming $lastlogin['lastlogin'] is a correct Date format string you could suffice with doing something like:

$then = new DateTime($lastlogin['lastlogin']);
$now = new DateTime("now");
echo $then->diff($now)->format('%a days');

edit: you can follow this guide to get different outputs.

Edited by Traevel: added DateInterval::format reference


ty for your help worked perfect ty x

Edited by janicemurby: typo error

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.