Hello in a PHP Script i have the following MySQL Query
$query_players = "SELECT (current_timestamp -`Online_since`) AS `Since` FROM `streams` WHERE `Team` = $temp AND `Online` = 1 ORDER BY `Viewers` DESC";
then i have:
$since = round($obj_players->Since /3600);
As you probably can imagine $since should contain how long the player is already online in hours. Strangely it has wrong results. Its like the time goes faster in MySQL 😛
For example after about 15 minutes it already shows “Online since 1 hour” another approximately 30 mins later it already shows 2 hours and so on.
Anyone know what could be wrong? Maybe current_timestamps is the problem?
current_timestampis not really measured in seconds. So dividing the difference by 3600 doesn’t yield hours, but some arbitrary value.The difference after 18 minutes is
1800andround(1800/3600) = round(0.5)gives of course1.Depending on your real column type use either
timediff()ortimestampdiff()for your calculation.