I am making a medical appointment system, and I have the following problem:
I have a form that specifies the range of dates for the doctor's care and specialty, another range of time during the day, and 7 checkboxes indicating each day of the week
<form action="" method="post">
<label>Fecha Inicio</label>
<input type="date" name="startdate"><br>
<label>Fecha Inicio</label>
<input type="date" name="enddate"><br>
<label>Hora Inicio</label>
<input type="time" name="starttime"><br>
<label>Hora Final</label>
<input type="time" name="endtime"><br>
<input type="checkbox">Lunes
<input type="checkbox">Martes
<input type="checkbox">Miercoles
<input type="checkbox">Jueves
<input type="checkbox">Viernes
<input type="checkbox">Sabado
<input type="checkbox">Domingo<br>
<button type="submit">enviar</button><br><br>
</form>
And with this code I loop through the date range, the time range every 30 minutes,
<?php
$StartTime= $_POST["starttime"];
$EndTime = $_POST["endtime"];
function get_minutes ( $start, $end ) {
while ( strtotime($start) <= strtotime($end) ) {
$minutes[] = date("h:i A", strtotime( "$start" ) );
$start = date("h:i A", strtotime( "$start + 30 mins")) ;
}
return $minutes;
}
$minutes = get_minutes($StartTime, $EndTime);
foreach($minutes as $minute) {
echo $minute .'<br />';
}
$begin = new DateTime( $_POST["startdate"] );
$end = new DateTime( $_POST["enddate"] );
$diasdisponibles = [];
for($i = $begin; $i <= $end; $i->modify('+1 day')){
echo $i->format("Y-m-d")."<br>";
}
?>
But I need it to check if the date range falls between the days of the selected checkboxes in order to insert them into the database: These would be my programmingdoctor tables :
As you can see, the record has a date from December 13 to 18, that would be from a Wednesday to Monday of the following week, but in the columns of the days of the week the only active days are Thursday and Sunday, that is, two business days. While the record is being made, at the same time another table is affected ticketscita :
Where I register the dates of the two working days of the specified range, and the hours of attention of the entered time range (every 30 min) with their respective status.
And I don't know how I could filter those dates where they fall on Thursday and Sunday. Any suggestion? Thanks in advance.
You can use the SQL DATE_FORMAT function to obtain the day of the week and with this you can make your query Clarify that the value returned by the same function is an integer between 0 and 6 where 0 corresponds to Sunday and so on until Saturday
With this you could filter by those appointments that fell Thursday or Sunday, if you want other specific days you can vary the IN numbers