1
I have a Mysql table called apartamento_data
, in it there are dates that the apartment is rented, ie unavailable for rent. Each line a date, so:
2017-05-31 2017-06-01 2017-06-04 2017-06-05 2017-06-06
What I need, make a query and list these dates grouped by period, ie, I take the days that are consecutive and list only the first and the 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 is 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 date handling in PHP, within the foreach
, right?
need to break by month? anyway, post your current query to help ;)
– rLinhares
Why are 6 dates only 4? Because they are continuous periods? It would not be convenient to create "data_start" and "data_end" columns instead of registering them in separate rows?
– Woss
Oops, I edited the question, I spelled it wrong. @Andersoncarloswoss would be yes, but the database is not mine, it’s the client’s, I’m just doing this query to generate an XML
– caiocafardo
Interesting your question, but I have a doubt, the date of beginning and end of the lease are on different lines?
– Wees Smith
@Weessmith yes. Each row of the table has a date. That’s great difficulty. I need to know when the difference between them is greater q a day and treat (know when it’s greater than a day I can do)
– caiocafardo
I still don’t understand these dates rsrs, if I book an apartment for three days, the bank will have three records, one for each day? This?
– lpFranz
@Ipfranz that’s right!
– caiocafardo