PHP中的两个日期之间的完整日期? [英] Full Days between two dates in PHP?
本文介绍了PHP中的两个日期之间的完整日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将MySQL表中的日期存储为yyyy-mm-dd(或典型的MySQL'date'格式)。如何才能找出剩下多少整天呢?
例如,如果我有:
2011-03-05
它会说:
17更多天
解决方案
在PHP中:
$ days =(strtotime date) - time())/ 86400;
在MySQL中:
SELECT
((UNIX_TIMESTAMP(date) - UNIX_TIMESTAMP())/ 86400)AS days
FROM table;
或者@coreyward表示(在MySQL中):
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / pre>
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;
这篇关于PHP中的两个日期之间的完整日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文