I have a table in MySQL called apartamento_data
, in it there are dates that the apartment is rented, that is, unavailable for rent. Each row a date, like this:
2017-05-31 2017-06-01 2017-06-04 2017-06-05 2017-06-06
What I need, to do a query and list these dates grouped by period, that is, I take the days that are consecutive and only the first and last, in the example above would look like this:
de 2017-05-31 até 2017-06-01 de 2017-06-04 até 2017-06-06
How to do this via PHP? My query looks like this:
SELECT apartamento_data.data_locado FROM apartamento
LEFT JOIN apartamento_data ON apartamento.id = partamento_data.idapartamento
WHERE apartamento.id=:qualApartamento
ORDER BY apartamento_data.data_locado ASC
But I believe I have to do this sort of date processing in PHP, within foreach
, right?