Convert seconds to minutes

0

On the base date it records the seconds online of each user, but it gets type numbers (example): 23631. I would like to convert these numbers in minutes, how do I do it?

<?php
$userstats_a = mysql_query("SELECT * FROM user_st");
while($oi = mysql_fetch_assoc($userstats_a)){
?>

<?php echo $oi['OnlineTime']; ?>

<?php } ?>
    
asked by anonymous 04.09.2017 / 19:55

2 answers

4

ideone example

<?php
$userstats_a = mysql_query("SELECT * FROM user_stats INNER JOIN users ON user_stats.id = users.id WHERE users.Rank <5 ORDER BY user_stats.OnlineTime DESC LIMIT 3");
while($userstats = mysql_fetch_assoc($userstats_a)){
?>

<?php echo $userstats['OnlineTime']/60; ?>

<?php } ?>
  

If you want only the whole part:

<?php echo (int)($userstats['OnlineTime']/60); ?>
  

the rest of the division

<?php echo ($userstats['OnlineTime'] % 60); ?>
    
04.09.2017 / 20:26
5

Just divide by 60, and you will have the time in minutes. In the query, it can be done as follows:

SELECT 
    (OnlineTime/60) as minutos
FROM user_stats 
INNER JOIN users ON user_stats.id = users.id 
WHERE users.Rank <5 
ORDER BY user_stats.OnlineTime DESC 
LIMIT 3
    
04.09.2017 / 19:57