Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Server Development
Habbo Retros
Habbo Q&A
Help with last online on staff page
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Haid" data-source="post: 433067" data-attributes="member: 10450"><p>That will show the hour that they were last online, for example if they were last online last night at 11pm it will still show 23 hours ago.</p><p>You need to use a function to get the relative time in relation to the timestamp you give it, when I did our HK I just found one online as it's standalone from Laravel which uses Carbon. You could use Carbon if you needed more options but this small function does what you want for a simple last online, you could even remove the second part which is for timestamps in the future as that will never occur in this case.</p><p></p><p>[CODE]</p><p>function time2str($ts) {</p><p> if(!ctype_digit($ts)) {</p><p> $ts = strtotime($ts);</p><p> }</p><p> $diff = time() - $ts;</p><p> if($diff == 0) {</p><p> return 'now';</p><p> } elseif($diff > 0) {</p><p> $day_diff = floor($diff / 86400);</p><p> if($day_diff == 0) {</p><p> if($diff < 60) return 'just now';</p><p> if($diff < 120) return '1 minute ago';</p><p> if($diff < 3600) return floor($diff / 60) . ' minutes ago';</p><p> if($diff < 7200) return '1 hour ago';</p><p> if($diff < 86400) return floor($diff / 3600) . ' hours ago';</p><p> }</p><p> if($day_diff == 1) { return 'Yesterday'; }</p><p> if($day_diff < 7) { return $day_diff . ' days ago'; }</p><p> if($day_diff < 31) { return ceil($day_diff / 7) . ' weeks ago'; }</p><p> if($day_diff < 60) { return 'last month'; }</p><p> return date('F Y', $ts);</p><p> } else {</p><p> $diff = abs($diff);</p><p> $day_diff = floor($diff / 86400);</p><p> if($day_diff == 0) {</p><p> if($diff < 120) { return 'in a minute'; }</p><p> if($diff < 3600) { return 'in ' . floor($diff / 60) . ' minutes'; }</p><p> if($diff < 7200) { return 'in an hour'; }</p><p> if($diff < 86400) { return 'in ' . floor($diff / 3600) . ' hours'; }</p><p> }</p><p> if($day_diff == 1) { return 'Tomorrow'; }</p><p> if($day_diff < 4) { return date('l', $ts); }</p><p> if($day_diff < 7 + (7 - date('w'))) { return 'next week'; }</p><p> if(ceil($day_diff / 7) < 4) { return 'in ' . ceil($day_diff / 7) . ' weeks'; }</p><p> if(date('n', $ts) == date('n') + 1) { return 'next month'; }</p><p> return date('F Y', $ts);</p><p> }</p><p>}</p><p>[/CODE]</p><p></p><p>You can then just give it your timestamp.</p><p>[CODE] time2str($row['last_online']) [/CODE]</p><p></p><p><img src="http://i.haidyn.me/9fee04d01.png" alt="" class="fr-fic fr-dii fr-draggable " style="" /></p></blockquote><p></p>
[QUOTE="Haid, post: 433067, member: 10450"] That will show the hour that they were last online, for example if they were last online last night at 11pm it will still show 23 hours ago. You need to use a function to get the relative time in relation to the timestamp you give it, when I did our HK I just found one online as it's standalone from Laravel which uses Carbon. You could use Carbon if you needed more options but this small function does what you want for a simple last online, you could even remove the second part which is for timestamps in the future as that will never occur in this case. [CODE] function time2str($ts) { if(!ctype_digit($ts)) { $ts = strtotime($ts); } $diff = time() - $ts; if($diff == 0) { return 'now'; } elseif($diff > 0) { $day_diff = floor($diff / 86400); if($day_diff == 0) { if($diff < 60) return 'just now'; if($diff < 120) return '1 minute ago'; if($diff < 3600) return floor($diff / 60) . ' minutes ago'; if($diff < 7200) return '1 hour ago'; if($diff < 86400) return floor($diff / 3600) . ' hours ago'; } if($day_diff == 1) { return 'Yesterday'; } if($day_diff < 7) { return $day_diff . ' days ago'; } if($day_diff < 31) { return ceil($day_diff / 7) . ' weeks ago'; } if($day_diff < 60) { return 'last month'; } return date('F Y', $ts); } else { $diff = abs($diff); $day_diff = floor($diff / 86400); if($day_diff == 0) { if($diff < 120) { return 'in a minute'; } if($diff < 3600) { return 'in ' . floor($diff / 60) . ' minutes'; } if($diff < 7200) { return 'in an hour'; } if($diff < 86400) { return 'in ' . floor($diff / 3600) . ' hours'; } } if($day_diff == 1) { return 'Tomorrow'; } if($day_diff < 4) { return date('l', $ts); } if($day_diff < 7 + (7 - date('w'))) { return 'next week'; } if(ceil($day_diff / 7) < 4) { return 'in ' . ceil($day_diff / 7) . ' weeks'; } if(date('n', $ts) == date('n') + 1) { return 'next month'; } return date('F Y', $ts); } } [/CODE] You can then just give it your timestamp. [CODE] time2str($row['last_online']) [/CODE] [IMG]http://i.haidyn.me/9fee04d01.png[/IMG] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Server Development
Habbo Retros
Habbo Q&A
Help with last online on staff page
Top