开发者

PHP MySQL - getting "days and hours" left of DATETIME

开发者 https://www.devze.com 2023-04-10 18:05 出处:网络
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?

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().

0

精彩评论

暂无评论...
验证码 换一张
取 消