PHP查找日期之间的差异 [英] PHP Finding the difference between dates

查看:103
本文介绍了PHP查找日期之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何使用PHP计算两个日期之间的差异?

我有一个PHP数组,以2012-04-04的形式保存电影发行日期。我将如何找到2个日期的差异。

I have a PHP array that holds film release dates in the form of "2012-04-04" as an example. How would i go about finding the difference of 2 dates.

例如 -

2012-04-04

2012-04-04

2012-03-31

2012-03-31

预期回应 - 5天差异

Expected response - 5 days difference

推荐答案

$d1 = new DateTime('2012-04-04');
$d2 = new DateTime('2012-03-31');

$interval = $d1->diff($d2);

echo $interval->format('%R%a days');

这篇关于PHP查找日期之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆