我收到上述錯誤的代碼的最後一行,我已經試過的答案,但,這並不似乎工作開捕致命錯誤:類的DateTime的對象無法轉換爲字符串
if (isset($_GET['logout'])) {
$name = $_SESSION["username"];
date_default_timezone_set('Asia/Kolkata');
$today = date('Y-m-d');
$time = new DateTime(date('H:i:s'));
$statement = $db->prepare("SELECT `logintime` FROM `attendance` WHERE empid=? AND date_t=?");
$statement->bind_param("ss", $name, $today);
$statement->execute();
$statement->bind_result($logintime);
while ($statement->fetch()) {
}
$logintime = new DateTime($logintime);
$interval = $logintime->diff($time);
$hours = $interval->format('%h');
$minutes = $interval->format('%i');
$workinghours = $hours + $minutes/60;
$stmt = $db->prepare("UPDATE `attendance` SET `logouttime`=? ,`workinghours`=? WHERE empid=? AND date_t=?");
$stmt->bind_param("ssss", $time, $workinghours, $name, $today);
$run = $stmt->execute();
}
哪裏是錯誤? –
在最後一行$ run = $ stmt-> execute() – gANDALF
您必須使用[format](http://php.net/manual/en/datetime.format.php)方法 – Scuzzy