Good evening.
Using PHP, I search for data with MySQL. The table has the following structure:
ID | dataHoraInicio | dataHoraTermino |
1 | 2017-05-08 11:28:40 | 2017-05-08 17:52:12 |
2 | 2017-05-08 18:34:02 | 2017-05-10 09:02:57 |
3 | 2017-05-10 09:44:31 | 2017-05-10 13:22:10 |
Assuming you only have these 3 records in the table, in a simple query, without WHERE, they would logically return all 3 rows.
Note that the first record starts on 08, at 11:28:40, and ends the same day at 17:52:12.
The second record starts on the same day as record 1, but only ends two days later, at 09:02:57 on the 10th.
The third record starts and ends the same day as the first record.
My question would be to "slice" the second record so that the query output looks like:
ID | dataHoraInicio | dataHoraTermino |
1 | 2017-05-08 11:28:40 | 2017-05-08 17:52:12 |
2 | 2017-05-08 18:34:02 | 2017-05-08 23:59:59 | <-- hora final alterada
2b | 2017-05-09 00:00:00 | 2017-05-09 23:59:59 | <-- dia "fatiado"
2c | 2017-05-10 00:00:00 | 2017-05-10 09:02:57 | <-- hora inicial alterada
3 | 2017-05-10 09:44:31 | 2017-05-10 13:22:10 |
The idea is that in each line returned, there is no "overflow" from the time to the next day, but rather "fatie", indicating each specific day.
The ID does not matter in the final result. I tried 3 ways, but either added days beyond what was expected, or did not complete the times as it should.
All tips will be welcome, whether solving via PHP, or directly in the SQL query. Hugs.