i want a php function to convert a unix time stamp to like this:
15 seconds
or
45 minutes
or
3 hours
and not like this : 2sec
If this is for a website, you might consider Timeago. Otherwise the algorithm is pretty straightforward. Something like:
$diff = $date - $now;
if ($diff > 2 * ONE_YEAR)
return sprintf("%d years", round($diff / ONE_YEAR));
else if ($diff > ONE_YEAR)
return "1 year";
else if ($diff > 2 * ONE_MONTH)
return sprintf("%d months", round($diff / ONE_MONTH));
...etc...