计算MySQL和PHP日期差异 [英] Calculating MySQL and PHP date difference in days
本文介绍了计算MySQL和PHP日期差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码
$ ArrivalDate = $ variants_data ['ArrivalDate'];
$ daydiff = floor((abs(strtotime(date(d / m / Y)) - strtotime($ ArrivalDate))/(60 * 60 * 24)))
输出
< td>'。$ daydiff。'< / td>
结果
我得到93天而不是26天使用此计算器获得26天 http://easycalculation.com/date-day/number -of-days.php )
ArrivalDate value = 2013-05-03 from MySQL表,它由于运输而改变延迟等。
如何在PHP中实现?
解决方案
p>尝试这个
$ daydiff = floor((abs(strtotime(date(Ymd)) - strtotime($ ArrivalDate ))/(60 * 60 * 24)));
只需更改您当前的日期函数格式,就可以给出正确的答案26天。 >
I am trying to calculate a date difference in days using MySQL and PHP date.
My code
$ArrivalDate = $variants_data['ArrivalDate'];
$daydiff=floor((abs(strtotime(date("d/m/Y")) - strtotime($ArrivalDate))/(60*60*24)));
Output
<td>'.$daydiff.'</td>
Results I get 93 days instead of 26 days (got 26 days using this calculator http://easycalculation.com/date-day/number-of-days.php)
ArrivalDate value = 2013-05-03 from MySQL table and it changes due to transport delays, etc.
How can I achieve this in PHP?
解决方案
try this
$daydiff=floor((abs(strtotime(date("Y-m-d")) - strtotime($ArrivalDate))/(60*60*24)));
just change your current date function format so it will give your correct answer means 26 days.
这篇关于计算MySQL和PHP日期差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文