查找PHP或MySQL中两个日期之间的差异

问题描述:

此查询不返回1月的记录,但返回2月的记录.

This query does not return the records for january, but it returns records for february.

SELECT EventAsstCharged,CustomerName,EventID ,EventName,EventExpectedCharges,EventActuallyCharged,EventUserCharged,date_format(EventDate,'%d-%m-%Y') as EventDate ,EventTime FROM tblevent WHERE Status=1 AND date_format(EventDate,'%d-%m-%Y') between '01-01-2011' AND '20-02-2011' AND EntryUser=2 AND Status=1 ORDER BY EventID DESC

如何使用PHP或MySQL查找两个日期之间的年龄?

How to find the age between two dates using PHP or MySQL?


2009-09-24 21:09:36     2010-03-04 13:24:58

<?php
$diff = strtotime('2010-03-04 13:24:58') - strtotime('2009-09-24 21:09:36');
echo "Difference is $diff seconds\n";
$days = floor($diff/(3600*24));
echo "Difference is $days days\n";