更新时间:2023-11-29 12:45:46
在PHP中:
$ days =(strtotime date) - time())/ 86400;
在MySQL中:
SELECT
((UNIX_TIMESTAMP(date) - UNIX_TIMESTAMP())/ 86400)AS days
FROM table;
或者@coreyward表示(在MySQL中):
I have dates stored in my MySQL table as yyyy-mm-dd (or typical MySQL 'date' format). How can I find out how many full days are left until then?
Like, for example, if I had:
2011-03-05
It would say:
17 More Days
In PHP:
$days = (strtotime($date) - time()) / 86400;
In MySQL:
SELECT
((UNIX_TIMESTAMP(date) - UNIX_TIMESTAMP()) / 86400) AS days
FROM table;
Or as @coreyward stated (in MySQL):
SELECT
DATEDIFF(UNIX_TIMESTAMP(date,NOW()) AS days
FROM table;