This is part of a simple project that logs payroll hours as a datetime object in MySQL 5.5. I am trying to compare two datetime values to see if they are at least 30 minutes apart. Sounds simple enough but the value of $lastshiftend keeps being set to the same value as $mealendtime and I don't see where or how. That seems to be the only problem but there definitely could be other things I am missing. TIA.
if ($result = mysqli_query($conn, $select)) {
$row_count = mysqli_num_rows($result);
if($row_count == 1) {
// 30 Minute Meal Break
$lastshiftend = new DateTime($row[3]);
$mealendtime = new DateTime('NOW');
$mealtime = $mealendtime->diff($lastshiftend);
$mealminend = $lastshiftend->add(new DateInterval(PT30M));
// $mealminend = $lastshiftend->modify('+ 30 minute');
if($mealendtime < $mealminend) {
echo '<br>Colorado State law requires meal breaks to be at least 30 minutes in length.';
echo '<hr><a href="./index.html">Main Menu</a>';
} else {
echo 'Log it!';
// header("Location: ./ActionClockIn.php");
}
} else {
echo 'Error! If you ended up here something broke!.';
echo '<hr><a href="./index.html">Main Menu</a>';
}
}