我的日期以yyyy-mm-dd(或典型的MySQL“日期”格式)存储在我的MySQL表中。我如何才能知道在那之前还剩下整整几天的时间?
例如,如果我有:
2011-03-05
它会说:
17 More Days
在PHP中:
$days = (strtotime($date) - time()) / 86400;
在MySQL中:
SELECT ((UNIX_TIMESTAMP(date) - UNIX_TIMESTAMP()) / 86400) AS days FROM table;
或如@coreyward所述(在MySQL中):
SELECT DATEDIFF(UNIX_TIMESTAMP(date,NOW()) AS days FROM table;