日期之间的差异 [英] Difference between dates
问题描述
可能的重复:
日期之间的差异
如何使用php计算两个日期之间的日期差异
2010-09-24 和 2010-09-25
。我想检查这两个日期之间的区别是1天。
我不需要获得 86400
的值,这意味着有一天在几秒钟内。
不要忘记,它可以是月28日,28日,29日,30日,31日。
感谢。
我现在有什么,但当月份有所不同时,它不起作用:
$ strto = strtotime($ date);
$ d1 = date('d',$ strto);
$ d2 = date('d',time());
echo $ d2- $ d1;
您可以使用 strtotime 以获得
<$ p $之间的秒数p>
echo abs(strtotime('2010-09-24') - strtotime('2010-09-25'));
Possible Duplicates:
Difference between dates
How to calculate the date difference between 2 dates using php
So, I have two dates. For instance, 2010-09-24
and 2010-09-25
. I want to check if between those two dates the difference is 1 day.
I don't need to get a value of 86400
which means one day in seconds.
Don't forget that it can be 28, 28, 29, 30, 31 days in month.
Thanks.
What I have right now, but it doesn't work when there is difference between months:
$strto = strtotime($date);
$d1 = date('d', $strto);
$d2 = date('d', time());
echo $d2- $d1;
You can use strtotime to get the number of seconds in between
echo abs(strtotime('2010-09-24') - strtotime('2010-09-25'));
这篇关于日期之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!