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

Bha*_*mar 2 php mysql

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

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
Run Code Online (Sandbox Code Playgroud)

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

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

ZZ *_*der 6

<?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";
Run Code Online (Sandbox Code Playgroud)