1
Good night.
Using PHP, I search 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, would logically return the 3 rows.
Note that the first entry starts on the 8th at 11:28:40 and ends on the same day at 17:52:12.
The second entry starts on the same day as record 1, but ends only two days later, at 09:02:57 on day 10.
The third record starts and ends on the same day as the first record.
My question would be to "slice" the second record, so that the output of the query is as:
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 returned line, there is no "overflow" of the time for the next day, but rather that it "fatigues", indicating each specific day.
The ID does not matter in the final result. I tried 3 ways, but either add days beyond the expected, or do not complete the schedules as it should.
Any tip will be welcome, either solving via PHP, or directly in the SQL query. Hugs.
Why do you need to "slice"? Can’t work with the dates and times as it comes? Yeah, maybe to solve your problem you don’t need to do the "slicing"
– David
Opa David, good night. I need it because this slice will be used in another part of the script. The results need yes, come out as explained in the question. Hugs.
– Guttemberg