There is a courier table of the form:

 region, courier, date_from, date_to 

date_from and date_to are the dates from which the courier is busy.

A request also comes to this page with two dates - you need to select all couriers that were at work at this time. How to do it?

  • what it means at "this time." All this time or at least one second from this time? - Mike
  • In which format is the time stored in the database and in what format do you submit from the form? - Bert
  • who were at work at this time enough touch? necessarily intersection? Required full coverage? - Akina
  • In the datetime database, from the form - datetime-local, the Courier left and went to another city - if I press the button - to get couriers to work with such - for such time - all couriers that were on the trip are displayed - Forever Young

1 answer 1

I do not know you understood correctly or not, if something is correct

 $date_from = strtotime($_POST['date_from']); $date_to = strtotime($_POST['date_to']); $result = "SELECT region, courier, date_from, date_to FROM courier WHERE UNIX_TIMESTAMP(date_from) >= '{$date_from}' AND UNIX_TIMESTAMP(date_to) <= '{$date_to}'"; 
  • Something is not working. From the form comes a request in the form 2017-01-01T00: 00 and in the table there is a cell of type datetime and values ​​of the form 2018-01-01 05:00:00. Maybe it's in the letter T in the request from the form? - Forever Young
  • Correct, thanks! WHERE UNIX_TIMESTAMP (date_from)> = '{$ dateFromOutput}' AND UNIX_TIMESTAMP (date_to) <= '{$ dateToOutput}' - Forever Young