i have this error when inserting $diff into my database table
time_in(time)
but im having this error
Catchable fatal error: Object of class DateInterval could not be converted to string
the error is in my query
What I have tried:
$conn = mysqli_connect(server,username,password)
or die (mysqli_error($conn));
mysqli_select_db($conn,database)
or die (mysqli_error($conn));
if ($now->format("H:i") > "22:00") {
$deadline = DateTime::createFromFormat("H:i", "22:00");
$diff = $now->diff($deadline);
echo "You are ".$diff->h." hours and ".$diff->i." minutes late";
} else if ($now->format("H:i") > "19:00") {
$deadline = DateTime::createFromFormat("H:i", "19:00");
$diff = $now->diff($deadline);
echo "You are ".$diff->h." hours and ".$diff->i." minutes late";
} else if ($now->format("H:i") > "16:00") {
$deadline = DateTime::createFromFormat("H:i", "16:00");
$diff = $now->diff($deadline);
echo "You are ".$diff->h." hours and ".$diff->i." minutes late";
} else if ($now->format("H:i") > "13:00") {
$deadline = DateTime::createFromFormat("H:i", "13:00");
$diff = $now->diff($deadline);
echo "You are ".$diff->h." hours and ".$diff->i." minutes late";
} else if ($now->format("H:i") > "10:00") {
$deadline = DateTime::createFromFormat("H:i", "10:00");
$diff = $now->diff($deadline);
echo "You are ".$diff->h." hours and ".$diff->i." minutes late";
} else if ($now->format("H:i") > "07:00") {
$deadline = DateTime::createFromFormat("H:i", "07:00");
$diff = $now->diff($deadline);
echo "You are ".$diff->h." hours and ".$diff->i." minutes late";
}
$query = "INSERT INTO `time_in`(`late`,`date_in`)
VALUES ('$diff',NOW())";
if (!$query) {
printf("Error: %s\n", mysqli_error($conn));
exit();
}
if($query = $conn ->query($query)){
echo "<br>successful";
} else {
echo "not successful";
}