seany123 Posted May 1, 2009 Share Posted May 1, 2009 here is the code... <?php function timeSince($urtime) { $seconds = (((time() - $urtime) / 1) % 60); $minutes = (intval((time() - $urtime) / 60) % 60); $hours = intval((time() - $urtime) / 3600); $days = intval((time() - $urtime) / 86400); $weeks = intval((time() - $urtime) / 604800); $months = intval((time() - $urtime) / 2419200); $years = intval((time() - $urtime) / 29030400); $result = array(); $result['years'] = ($years) ? sprintf('%u year%s,', number_format($years), ($years > 1) ? 's' : '') : FALSE; $result['months'] = ($months) ? sprintf('%u month%s,', number_format($months), ($months > 1) ? 's' : '') : FALSE; $result['weeks'] = ($weeks) ? sprintf('%u week%s,', number_format($weeks), ($weeks > 1) ? 's' : '') : FALSE; $result['days'] = ($days) ? sprintf('%u day%s,', number_format($days), ($days > 1) ? 's' : '') : FALSE; $result['hours'] = ($hours) ? sprintf('%u hour%s,', number_format($hours), ($hours > 1) ? 's' : '') : FALSE; $result['minutes'] = ($minutes) ? sprintf('%u minute%s', $minutes, ($minutes > 1) ? 's' : FALSE) : FALSE; $result['seconds'] = ($seconds) ? sprintf('%s %u second%s',($minutes) ? 'and' : '', $seconds, ($seconds > 1) ? 's' : FALSE) : FALSE; return (count($result) == 0) ? 'Never' : implode(' ', $result).' ago'; } ?> can anyone help me change this code, so if seconds is <= 1 then it will echo "NOW!" Quote Link to comment Share on other sites More sharing options...
Gighalen Posted May 1, 2009 Share Posted May 1, 2009 if-else? lolz Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 1, 2009 Share Posted May 1, 2009 <?php function timeSince($urtime) { $seconds = (((time() - $urtime) / 1) % 60); $minutes = (intval((time() - $urtime) / 60) % 60); $hours = intval((time() - $urtime) / 3600); $days = intval((time() - $urtime) / 86400); $weeks = intval((time() - $urtime) / 604800); $months = intval((time() - $urtime) / 2419200); $years = intval((time() - $urtime) / 29030400); $result = array(); $result['years'] = ($years) ? sprintf('%u year%s,', number_format($years), ($years > 1) ? 's' : '') : FALSE; $result['months'] = ($months) ? sprintf('%u month%s,', number_format($months), ($months > 1) ? 's' : '') : FALSE; $result['weeks'] = ($weeks) ? sprintf('%u week%s,', number_format($weeks), ($weeks > 1) ? 's' : '') : FALSE; $result['days'] = ($days) ? sprintf('%u day%s,', number_format($days), ($days > 1) ? 's' : '') : FALSE; $result['hours'] = ($hours) ? sprintf('%u hour%s,', number_format($hours), ($hours > 1) ? 's' : '') : FALSE; $result['minutes'] = ($minutes) ? sprintf('%u minute%s', $minutes, ($minutes > 1) ? 's' : FALSE) : FALSE; $result['seconds'] = ($seconds) ? sprintf('%s %u second%s',($minutes) ? 'and' : '', $seconds, ($seconds > 1) ? 's' : FALSE) : FALSE; if ($seconds <= 1) return "NOW!"; else return (count($result) == 0) ? 'Never' : implode(' ', $result).' ago'; } ?> Like that? Quote Link to comment Share on other sites More sharing options...
seany123 Posted May 1, 2009 Author Share Posted May 1, 2009 yes thank you ken that worked but I have just come across a different error now. its displaying things like "1 day, 31 hours, 56 minutes and 33 seconds ago" why is it display 31 hours? there's only 24 hours in a day EDIT: and another error, if the user have never logged in... then it will echo NOW instead of never Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 1, 2009 Share Posted May 1, 2009 You forgot modulo in hour and possibly. As for the other error, not my problem. Quote Link to comment Share on other sites More sharing options...
seany123 Posted May 1, 2009 Author Share Posted May 1, 2009 You forgot modulo in hour and possibly. As for the other error, not my problem. modulo?? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 1, 2009 Share Posted May 1, 2009 Google much? It's the '%' sign. If you don't know what that does, read it up. Quote Link to comment Share on other sites More sharing options...
seany123 Posted May 3, 2009 Author Share Posted May 3, 2009 a problem is for some reason the second i log in, it starts going up, even when i am still actively clicking links and refreshing pages etc. Quote Link to comment Share on other sites More sharing options...
seany123 Posted May 3, 2009 Author Share Posted May 3, 2009 ive tried editing it about but im still getting the same issue. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 3, 2009 Share Posted May 3, 2009 a problem is for some reason the second i log in, it starts going up, even when i am still actively clicking links and refreshing pages etc. Well that's what it should do. The function is called timeSince, so it only makes sense for it to go up. Quote Link to comment Share on other sites More sharing options...
seany123 Posted May 3, 2009 Author Share Posted May 3, 2009 right so what I need to do it have a query in a functions page which is called on every page... to set last_active to time() is that right? that way, the time will go up from the no pages have been loaded. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.