PHP MySQL - getting "days and hours" left of DATETIME
I have a MYSQL query that selects all rows that are less than 60 days old. I would like to display on my PHP page "x days and y hours left". What's the e开发者_Go百科asiest way to do this?
SELECT u.username, u.id, u.score, s.genre, s.songid, s.songTitle, s.timeSubmitted, s.userid, s.insWanted, s.bounty, COUNT(p.songid)
FROM songs s
LEFT JOIN users u
ON u.id = s.userid
LEFT JOIN posttracks p
ON s.songid = p.songid
WHERE paid=1 AND s.timeSubmitted >= ( CURDATE() - INTERVAL 60 DAY )
GROUP BY s.timeSubmitted DESC
LIMIT 15
In PHP try something along these lines when looping over your rows:
$then = strtotime($futureDateAsString);
$diff = $then - time();
echo sprintf("%s days and %s hours left", date('z', $diff), date('G', $diff));
Try TIMEDIFF()
.
精彩评论