亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

計算兩個日期和小時之間的小時分鐘和天數

計算兩個日期和小時之間的小時分鐘和天數

PHP
飲歌長嘯 2022-07-09 16:45:35
我有一個 PHP 和 MySQL 代碼,它應該計算兩個日期和小時之間的小時分鐘和天數。效果很好,只是比平時多增加了 20 小時 20 分鐘。我刪除了 DATE 部分并手動輸入日期和時間,它工作正常。我不明白會發生什么。    $fecha = $row["fecha"];        $data= $row["hora"];$start = strtotime("$fecha $hora"); $currentDate = date("Y-m-d");$currentTime = date("H:i:s");$currentDate =  date("Y-m-d H:i:s", strtotime($currentDate .$currentTime));$end = strtotime("$currentDate"); $totaltime = ($end - $start)  ; $hours = intval($totaltime / 3600);   $seconds_remain = ($totaltime - ($hours * 3600)); $minutes = intval($seconds_remain / 60);   $seconds = ($seconds_remain - ($minutes * 60));$statusfichaje= $row["status"];if ($statusfichaje == Start){echo '<td>Trabajando'.$hours.':'.$minutes.':'.$seconds.' </td>';}else{echo '<td>'. $row["status"] .'</td>';}編輯2019-12-29 21:27:50 開始。2019 年 12 月 31 日結束 0:51:50 = 47:51:16如您所見,它的計算很糟糕。
查看完整描述

2 回答

?
RISEBY

TA貢獻1856條經驗 獲得超5個贊

像這樣一個簡單的例子就可以完成這項工作:


$mydatetime = new DateTime();

$datefromdb = new DateTime('2018-03-05 10:10:00');

$interval = $mydatetime->diff($datefromdb);

$date_count = $interval->format('%y years %m months %a days %h hours %i minutes %s seconds');

echo $date_count;

這是你應該工作的代碼


$fecha = $row["fecha"];

$data= $row["hora"];

$start = strtotime("$fecha $data"); 



$currentDate = date("Y-m-d");

$currentTime = date("H:i:s");

$currentDate =  date("Y-m-d H:i:s", strtotime($currentDate .$currentTime));


$end = strtotime("$currentDate"); 




$totaltime = ($end - $start)  ; 


$hours = intval($totaltime / 3600);   

$seconds_remain = ($totaltime - ($hours * 3600)); 


$minutes = intval($seconds_remain / 60);   

$seconds = ($seconds_remain - ($minutes * 60));

$statusfichaje= $row["status"];

if ($statusfichaje == $start){echo '<td>Trabajando'.$hours.':'.$minutes.':'.$seconds.' </td>';}else{echo '<td>'. $row["status"] .'</td>';}



查看完整回答
反對 回復 2022-07-09
?
繁花如伊

TA貢獻2012條經驗 獲得超12個贊

問題出在字符串中。

  $data= $row["hora"];

我用這個

$start = strtotime("$fecha $hora");

并且不要花時間只計算幾天。


查看完整回答
反對 回復 2022-07-09
  • 2 回答
  • 0 關注
  • 156 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號