我正在使用PHP和MySQL,并希望计算两个日期时间之间的日期时间差.我有一个消息表,在该表中createdate是一个字段.我想从格式中找出当前日期的日期和时间差异1 day 2 hours ago.最好的方法是什么?
我得到了这样的日期之间的时差:
$time1 = "2013-02-25 12:00:00";
$time2 = "2013-01-01 12:00:00";
$tdiff = strtotime($time1) - strtotime($time2);
Run Code Online (Sandbox Code Playgroud)
我想要提取日,小时和分钟$tdiff.输出应该像:35 days 6 hours 14 minutes
我真的搜索并尝试自己做点什么.但我无法获得真正的价值.
----编辑----我可以找到日期差异.我想从计算时间中提取天数,小时数,分钟数......
----编辑2 ----这是我完整的mysql代码
select (
select avg(UNIX_TIMESTAMP(tarih)) from table1
where action in (6) and who = '".$user."' and dates between '".$date1."' and '".$date."'
) - (
select avg(UNIX_TIMESTAMP(tarih_saat)) from table2
where action in (6) and active = 1 and dates between '".$date1."' and '".$date2."
)
Run Code Online (Sandbox Code Playgroud)
此查询返回真实的时间值.此查询对我来说正常.结果如下:215922.结果类型为UNIX_TIMESTAPM.所以我想知道这个时间戳中有多少天,几小时和几分钟.