Onlinetime help

Status
Not open for further replies.

Mirreo

New Member
Mar 25, 2020
8
4
Hey guys, i need help with something. I tried implementing online_time to my ranking list on the Cosmic CMS.
I fetch the column table online_time from my users_settings table in my database and it's in seconds.
How do i convert the seconds to hh mm ss format?


PHP:
    public static function getOnlineTime($limit = 10)
    {

        return QueryBuilder::table('users_settings')->select('user_id')->select('online_time')->select('online_time')->orderBy('online_time', 'desc')->limit($limit)->get(); 

    }

This is the jquerybulder code rn, but how do i convert the outcome of this to hh mm ss?
 

Higoka

Active Member
Dec 16, 2018
174
74
$time is the timestamp returned from your getOnlineTime function then pass that value to the date function like so:
PHP:
$time = getOnlineTime();
// output converted result:
echo date('h:i:s', $time);
 

Mirreo

New Member
Mar 25, 2020
8
4
This is how it looks rn, not sure where to implement the date function without the code crashing..

PHP:
        $onlinetime = Community::getOnlineTime(6);
        foreach ($onlinetime as $item)

        {


            $item->player = Player::getDataById($item->user_id, array('username', 'look'));

        }
 

Higoka

Active Member
Dec 16, 2018
174
74
try this
PHP:
$onlinetime = Community::getOnlineTime(6);

foreach ($onlinetime as $item) {
    $item->online_time = date('h:i:s', $item->online_time);
    $item->player = Player::getDataById($item->user_id, array('username', 'look'));
}
 

Mirreo

New Member
Mar 25, 2020
8
4
try this
PHP:
$onlinetime = Community::getOnlineTime(6);
foreach ($onlinetime as $item) {
    $item->online_time = date('h:i:s', $item->online_time);
    $item->player = Player::getDataById($item->user_id, array('username', 'look'));
}

That did the trick, thanks man.
 
Status
Not open for further replies.

Users who are viewing this thread

Top