Ho risolto il problema con questo script, su $timestamp c'è il timestamp.
Codice PHP:
function getCreationDateTimeSince($timestamp)
{
$totaldelay = time() - strtotime($timestamp);
{
if($years=floor($totaldelay/31536000))
{
$totaldelay = $totaldelay % 31536000;
$getYear = '';
if ($years > 1)
$getYear=' anni fa';
else{
$getYear=' anno fa';
}
$timesince = $timesince.$years.$getYear;
return $timesince;
}
if($months=floor($totaldelay/2628000))
{
$totaldelay = $totaldelay % 2628000;
$getMonth = '';
if ($months > 1)
$getMonth=' mesi fa';
else{
$getMonth=' mese fa';
}
$timesince = $timesince.$months.$getMonth;
return $timesince;
}
if($days=floor($totaldelay/86400))
{
$totaldelay = $totaldelay % 86400;
$getDay = '';
if ($days > 1)
$getDay=' giorni fa';
else{
$getDay=' giorno fa';
}
$timesince = $timesince.$days.$getDay;
return $timesince;
}
if($hours=floor($totaldelay/3600))
{
$totaldelay = $totaldelay % 3600;
$getHour = '';
if ($hours > 1)
$getHour=' ore fa';
else{
$getHour=' ora fa';
}
$timesince = $timesince.$hours.$getHour;
return $timesince;
}
if($minutes=floor($totaldelay/60))
{
$totaldelay = $totaldelay % 60;
$getMinute = '';
if ($minutes > 1)
$getMinute=' minuti fa';
else{
$getMinute=' minuto fa';
}
$timesince = $timesince.$minutes.$getMinute;
return $timesince;
}
if($seconds=floor($totaldelay/1))
{
$totaldelay = $totaldelay % 1;
$getSecond = '';
if ($seconds > 1)
$getSecond=' secondi fa';
else{
$getSecond=' secondo fa';
}
$timesince = $timesince.$seconds.$getSecond;
return $timesince;
}
}
}