我喜歡這個日期之間的時間差:計算時間的流逝與PHP
$time1 = "2013-02-25 12:00:00";
$time2 = "2013-01-01 12:00:00";
$tdiff = strtotime($time1) - strtotime($time2);
我想從$tdiff
提取天,小時和分鐘。輸出應該是這樣的:35 days 6 hours 14 minutes
我真的搜索並嘗試自己做一些事情。但我無法獲得真正的價值。
----編輯---- 我可以找到日期差異。我想提取幾天,幾小時,從計算時間的分鐘......
---- EDIT 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."
)
該查詢返回給我真正的價值時間。這個查詢對我來說工作正常。結果如下:215922
。結果類型爲UNIX_TIMESTAPM。所以我想知道這個時間戳有多少天,幾小時和幾分鐘。
可能重複[如何計算兩個日期之間的差異使用PHP?](http://stackoverflow.com/questions/676824/how-以計算這兩個日期之間的差異使用PHP) – Rikesh 2013-02-25 09:20:29
http://www.php.net/manual/en/datetime.diff.php – Buksy 2013-02-25 09:21:01
這些日期是從數據庫最初來的嗎? – Cups 2013-02-25 09:21:18