Here is the code:
function longadata($data)
{
if(empty($data))
{
return "No date provided";
}
$periods = array(_segundo, _minuto, _hora, _dia, _semana, _mes, _ano, _decada);
$lengths = array("60", "60", "24", "7", "4.35", "12", "10");
$now = time();
$unix_date = strtotime($data);
if (empty($unix_date))
{
return "Bad date";
}
if ($now > $unix_date)
{
$difference = $now - $unix_date;
$tense = _atras;
}
else
{
$difference = $unix_date - $now;
$tense = _agora;
}
for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++)
{
$difference /= $lengths[$j];
}
$difference = round($difference);
if($difference != 1)
{
$periods[$j].= "s";
}
return "$difference $periods[$j] {$tense}";
}
No HTML:
<li class="published-date"><?php echo longadata("2017-08-28") ?></li>
No result:
3 MÊSS ATRÁS
I want to correct from "month" to "months" by the code, but I have to keep these codes because of "second", "minute", "year"
if($difference != 1)
{
$periods[$j].= "s";
}