$roomId = $_POST['roomId']; $currentCheckIn = Tools::formatToMYSQL($_POST['currentCheckIn']); $currentCheckOut = Tools::formatToMYSQL($_POST['currentCheckOut']); $checkIn = Tools::formatToMYSQL($_POST['checkIn']); $checkOut = Tools::formatToMYSQL($_POST['checkOut']); $current = array($currentCheckIn, $currentCheckOut); $needed = array($checkIn, $checkOut); $currentMin = new DateTime(min($current)); $currentMax = new DateTime(max($current)); $neededMin = new DateTime(min($needed)); $neededMax = new DateTime(max($needed)); // into the current date, they want a minumun range than current // --------- // ------- if ($neededMin >= $currentMin && $neededMax <= $currentMax) { $currentRoom = $model->getSingleRoomById($roomId); ?> <option selected value="<?php echo $currentRoom['room_id']; ?> "><?php echo $currentRoom['room']; ?> </option> <?php } // if the needed check-out is bigger than the current check out but the needed check in is in the current range // -------- // ------- if ($neededMax > $currentMax) { if ($neededMin >= $currentMin && $neededMin < $currentMax) {