0

Hey,

I hope all is good in your World, and thank you for reading this.

I am having a couple of issues with a bit of script, I struggling to see what is wrong.

The script in question is:

    function date_diff($str_start, $str_end) {
    $defdate = $str_start ;
    $str_start = strtotime($str_start) ;
    $str_end = strtotime($str_end) ;
    $nseconds = $str_end - $str_start ;
    $ndays = floor($nseconds / 86400) ;
    $nseconds = $nseconds % 86400 ;
    $nhours = floor($nseconds / 3600) ;
    $nseconds = $nseconds % 3600 ;
    $nminutes = floor($nseconds / 60) ;
    $nseconds = $nseconds % 60 ;
    $retString = "" ;

    if ($ndays > 0) {
        $retString .= $defdate ;
        return "@ ".$retString ;
    }
    if ($nhours > 0) {
        $retString .= " ".$nhours." hour" ;
        if ($nhours > 1)
        $retString .= "s" ;
    }
    if ($nminutes > 0) {
        $retString .= " ".$nminutes." minute" ;
        if ($nminutes > 1)
        $retString .= "s" ;
    }
        if (strcmp($retString, "") == 0) 
    $retString = "< 1 minute" ;
    return $retString." ago" ;

}

The error that this produces is:

Fatal error: Cannot redeclare date_diff() in /home/xxx/public_html/clips/ajaxfunc.php on line 59

Line 59 is the final }

Anyone know where I am going wrong?

Your assistance would be appreciated.

2
Contributors
2
Replies
10
Views
4 Years
Discussion Span
Last Post by squeak24
This topic has been dead for over six months. 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.