[英]finding hour difference between two times in php not working
我的 sql 表中有 2 次,例如 02:56:07pm 和 03:56:14pm,所以我將其轉換為:
$time1 = date("G:i:s", strtotime($row['timein'])); $time2 = date("G:i:s", strtotime($row['timeout']));
這給了我兩次 14:56:07 和 15:56:14
現在我試圖找到這兩次之間的小時數差異,我喜歡以下內容:
$difference = round(abs($time2 - $time1) / 3600,2); echo $difference;
但這里得到 0 作為答案,任何人都可以告訴我如何解決它,提前致謝
這對我有用:
使用strtotime將日期/時間字符串轉換為 Unix 時間戳(例如 163612416703)。 現在可以對時間進行計算。
$time1 = strtotime('02:56:07pm');
$time2 = strtotime('05:56:14pm');
$difference = date('H:i:s', ($time2 - $time1));
echo $difference; //03:00:07
玩弄格式等。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.