I want to find overlaping times between caterer and courier opened times I have those tables in mysql Table called caterer_openings
+-----------+---------+------------+----------+
| catererID | weekDay | openedFrom | openedTo |
+-----------+---------+------------+----------+
| 1 | 1 | 08:00 | 04:00 |
| 1 | 2 | 08:00 | 23:00 |
| 1 | 3 | 08:00 | 17:00 |
| 1 | 4 | 08:00 | 17:00 |
| 1 | 5 | 09:00 | 18:00 |
| 1 | 6 | 09:00 | 18:00 |
| 1 | 7 | 09:00 | 18:00 |
+-----------+---------+------------+----------+
Then i have table caterer_openings_exceptions, where is described exceptions.
+-----------+---------------+------------+----------+
| catererID | exceptionDate | openedFrom | openedTo |
+-----------+---------------+------------+----------+
| 1 | 2016-06-20 | 08:30 | 01:30 |
+-----------+---------------+------------+----------+
Table called courier_openings, that means courier will start delivering caterer foods at those times in weekday
+-----------+---------+------------+----------+
| courierID | weekDay | openedFrom | openedTo |
+-----------+---------+------------+----------+
| 1 | 1 | 10:00 | 01:00 |
| 1 | 2 | 10:00 | 18:00 |
| 1 | 3 | 10:00 | 17:00 |
| 1 | 4 | 10:00 | 17:00 |
| 1 | 5 | 10:00 | 23:00 |
| 1 | 6 | 10:00 | 23:00 |
| 1 | 7 | 10:00 | 23:00 |
+-----------+---------+------------+----------+
Then i have table courier_openings_exceptions
+-----------+---------------+------------+----------+
| courierID | exceptionDate | openedFrom | openedTo |
+-----------+---------------+------------+----------+
| 1 | 2016-06-19 | 10:30 | 19:00 |
+-----------+---------------+------------+----------+
I want to create sql query which finds nearest possible overlaped times
- For example current dateTime is 2016-06-19 11:00 and the next overlaping times should be 2016-06-19 10:30 - 2016-06-19 18:00
- For example current dateTime is 2016-06-19 19:00 and the next overlaping times should be on monday 2016-06-20 10:00 - 2016-06-20 01:30.
- If the _exceptions tables has no records then it should find overlaps only using _openigns table
I want to get these results via MySQL and PHP
Aucun commentaire:
Enregistrer un commentaire