查找PHP或MySQL中两个日期之间的差异 [英] Find difference between two dates in PHP or MySQL

查看:79
本文介绍了查找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";

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

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