I am trying to make a query to validate if a specific appointment already exists, since in the same period of time no other appointment should be generated. For this I consult the date of the appointment, the initial hour of the appointment and the final hour.
My dating table looks like this:
Then my query that more or less worked for me:
$query = $this->db->prepare("select * from events where ((e_time_start < ? AND e_time_end > ?) OR e_time_end > ? AND e_time_end < ? OR e_time_start > ? AND e_time_start < ?) AND e_date_event = ?;");
$query->execute([$time_start.':00', $time_end.':00', $time_start.':00', $time_end.':00', $time_start.':00', $time_end.':00', $date_start.'']);
$events = $query->fetchAll();
I should solve the following events regarding the information I have in the table but in some cases it does not solve them:
6am to 7am yes you should be able to add the appointment
7am to 8am should not be able to add the appointment
6am to 11am should not be able to add the appointment
8am to 11am should not be able to add the appointment
8am to 9am should not be able to add the appointment
9am to 10am should not be able to add the appointment
10am to 11am yes you should be able to add the appointment