如何找到两个日期之间的差异 [英] How to find the difference in days between two dates

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

问题描述


可能重复:

如何使用php查找两个日期之间的天数

如果我有两个日期 - 如何找到两个日期之间的真实差异?您必须考虑到闰年和每个月的天数。

If I have two dates - how do I find the real difference in days between two dates? You must take things like leap years and the number of days in each month into account.

在$ code> 2010-03- 29 和 2009-07-16

How many days are between something like 2010-03-29 and 2009-07-16?

推荐答案

strtotime 和简单的数学:

   $daylen = 60*60*24;

   $date1 = '2010-03-29';
   $date2 = '2009-07-16';

   echo (strtotime($date1)-strtotime($date2))/$daylen;

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

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