PHP MySQL - 获得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 easiest 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

2个回答



在PHP中循环遍历行时,请尝试以下几行:</ p>

  $  then = strtotime($ futureDateAsString); 
$ diff = $ then - time();
echo sprintf(“%s days and%s hours left”,date('z',$ diff),date('G' ,$ diff));
</ code> </ pre>
</ div>

展开原文

原文

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));



尝试 TIMEDIFF()</ code> 。</ p>
</ div>

展开原文

原文

Try TIMEDIFF().

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐