So, on my website, i have added a "last active" feature, so if someone is surfing the site, they can view when another users last page visit was.
so, every second, +1 is added to the $ts variable
what i have now, working and all, shows ONLY "NOW!", or ONLY "1 second", ONLY "___ seconds ago"... and so on
I have tred over, and over, and over to fix this to my liking, with more instances available, as an example, my current script will show somebody who is 13 months and 26 days inactive, just as "1 year", i want to see the "1 year, 1 month, and 26 days inactive"... or even simpler, just so it displays days/minutes/seconds/NOW!
function howlongtil($ts) {
$ts=$ts - time();
if ($ts<1)
// <1 second
return " NOW";
elseif ($ts==1)
// <1 second
return $ts." second";
elseif ($ts<60)
// <1 minute
return $ts." seconds";
elseif ($ts<120)
// 1 minute
return "1 minute";
elseif ($ts<60*60)
// <1 hour
return floor($ts/60)." minutes";
elseif ($ts<60*60*2)
// <2 hour
return "1 hour";
elseif ($ts<60*60*24)
// <24 hours = 1 day
return floor($ts/(60*60))." hours";
elseif ($ts<60*60*24*2)
// <2 days
return "1 day";
elseif ($ts<(60*60*24*7))
// <7 days = 1 week
return floor($ts/(60*60*24))." days";
elseif ($ts<60*60*24*30.5)
// <30.5 days ~ 1 month
return floor($ts/(60*60*24*7))." weeks";
elseif ($ts<60*60*24*365)
// <365 days = 1 year
return floor($ts/(60*60*24*30.5))." months";
else
// more than 1 year
return floor($ts/(60*60*24*365))." years";
};
anyone know how?