Convert seconds to minutes

Asked

Viewed 482 times

0

In the base date records the second onlines of each user, but it is numbers of type (example): 23631. I would like to convert these numbers into minutes, as I do?

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

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

<?php } ?>
  • 1

    It would not only be divided by 60, since each minute consists of 60 seconds?

  • divided by 60 ?!

  • Personal thank you!

2 answers

5

Just divide by 60, and you’ll have 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
  • Thanks friend!

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 only want the whole part:

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

the rest of the division

<?php echo ($userstats['OnlineTime'] % 60); ?>
  • Thank you was very simple :

Browser other questions tagged

You are not signed in. Login or sign up in order to post.