techiefreak05 Posted October 22, 2007 Share Posted October 22, 2007 How could I take the time(); function and put it against an old value of time(); from a database and display "XX minutes ago" Quote Link to comment https://forums.phpfreaks.com/topic/74368-how-to-determine-minutes-ago/ Share on other sites More sharing options...
darkfreaks Posted October 22, 2007 Share Posted October 22, 2007 <?php $time= time(); if($time=time()-3600) { echo " this post was posted an hour ago";}?> Quote Link to comment https://forums.phpfreaks.com/topic/74368-how-to-determine-minutes-ago/#findComment-375741 Share on other sites More sharing options...
roopurt18 Posted October 22, 2007 Share Posted October 22, 2007 http://us2.php.net/time Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT). You have two values that represent seconds. Take the difference and divide by 60 (seconds per minute)... Quote Link to comment https://forums.phpfreaks.com/topic/74368-how-to-determine-minutes-ago/#findComment-375745 Share on other sites More sharing options...
techiefreak05 Posted October 22, 2007 Author Share Posted October 22, 2007 Thanks, I came up with this: <?php $postedTime="1192909166"; $nowTime=time(); $diff=$nowTime-$postedTime; echo "Posted" . $diff . " seconds ago<br>"; echo "Posted " . $diff/60 . " minutes ago<br>"; echo "Posted " . $diff/3600 . " hours ago<br>"; echo "Posted " . $diff/86400 . " days ago<br>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/74368-how-to-determine-minutes-ago/#findComment-375764 Share on other sites More sharing options...
roopurt18 Posted October 22, 2007 Share Posted October 22, 2007 You might want to encapsulate the division with a call to floor(). Quote Link to comment https://forums.phpfreaks.com/topic/74368-how-to-determine-minutes-ago/#findComment-375766 Share on other sites More sharing options...
termn8r Posted October 22, 2007 Share Posted October 22, 2007 But if you want exact time. ##Last Touch is the last time the person clicked anything $seconds_ago = time() - $last_touch; ##How many Types of Time should we show? $list_number = 2; ##Month Check $months_ago = floor($seconds_ago / 2592000); if($months_ago > 0) { $seconds_left = $seconds_ago - ($months_ago * 2592000); $last_active = "$months_ago Months"; $active_length++; } ##Day Check $days_ago = floor($seconds_left / 86400); if($days_ago > 0) { $seconds_left = $seconds_left - ($days_ago * 86400); if($list_number > $active_length) { $active_length++; $last_active .= "$days_ago Days"; } } ##Hour Check $hours_ago = floor($seconds_left / 3600); if($hours_ago > 0) { $seconds_left = $seconds_left - ($hours_ago * 3600); if($list_number > $active_length) { $active_length++; $last_active .= "$hours_ago Hours"; } } ##Minute Check $minutes_ago = floor($seconds_left / 60); if($minutes_ago > 0) { $seconds_left = $seconds_left - ($minutes_ago * 60); if($list_number > $active_length) { $active_length++; $last_active .= "$minutes_ago Minutes"; } } ##Second Check if($seconds_left > 0) { if($list_number > $active_length) { $active_length++; $last_active .= "$seconds_left Seconds"; } } I just wrote this freehand, not 100% sure it is without flaw. Quote Link to comment https://forums.phpfreaks.com/topic/74368-how-to-determine-minutes-ago/#findComment-375777 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.