2
<?php
function timeAgo($time_ago){
$cur_time   = time();
$time_elapsed   = $cur_time - $time_ago;
$seconds    = $time_elapsed ;
$minutes    = round($time_elapsed / 60 );
$hours      = round($time_elapsed / 3600);
$days       = round($time_elapsed / 86400 );
$weeks      = round($time_elapsed / 604800);
$months     = round($time_elapsed / 2600640 );
$years      = round($time_elapsed / 31207680 );
// Seconds
if($seconds <= 60){
    echo "$seconds segundos atrás";
}
//Minutes
else if($minutes <=60){
    if($minutes==1){
        echo "um minuto atrás";
    }
    else{
        echo "$minutes minutos atrás";
    }
}
//Hours
else if($hours <=24){
    if($hours==1){
        echo "uma hora atrás";
    }else{
        echo "$hours horas atrás";
    }
}
//Days
else if($days <= 7){
    if($days==1){
        echo "ontem";
    }else{
        echo "$days dias atrás";
    }
}
//Weeks
else if($weeks <= 4.3){
    if($weeks==1){
        echo "à uma semana";
    }else{
        echo "$weeks semanas atrás";
    }
}
//Months
else if($months <=12){
    if($months==1){
        echo "um mês atrás";
    }else{
        echo "$months meses atrás";
    }
}
//Years
else{
    if($years==1){
        echo "um ano atrás";
    }else{
        echo "$years anos atrás";
    }
}
}
?>
<?php
  $curenttime=$date_uploaded;
  $time_ago =strtotime($curenttime);
  echo timeAgo($time_ago);
?>
Whereas $date_upload is equal to (dd-mm-yy hh:mm:ss) in the database.
This is the code, when I pull only one post it works, but when I pull several posts gives this error:
error: Cannot redeclare timeAgo() (Previously declared in C: xampp htdocs site poster.php:520) in)
It seems that in the file
poster.phphas a function with the same name as the one you posted (timeAgo), but can also be problem with adding files viainclude. Try to rename this function, and if you are usinginclude, try to change toinclude_once.– gustavox