How can I make a select by date and time

0

Well, what I initially intend is to do a while while showing me all the results of my column reservations. However I want to make a select that shows me the closest days and then the closest hours.

The name of my days column is "dialevant" and the name of my pick time is "horalevant", how can I do it to make a select that shows me the next days and then the time?

Thank you.

    
asked by anonymous 07.07.2016 / 06:25

1 answer

0

If the day and time are separated, then join them with DATETIMEFROMPARTS. Its format is:

DATETIMEFROMPARTS ( year, month, day, hour, minute, seconds, milliseconds )

So, try something like:

SELECT *
FROM reservas
WHERE DATETIMEFROMPARTS(
                       YEAR(dialevant),
                       MONTH(dialevant),
                       DAY(dialevant),
                       HOUR(horalevant),
                       MINUTE(horalevant),
                       0,
                       0) > DATETIME("SUA DATA AQUI")
ORDER BY DATETIMEFROMPARTS(
                       YEAR(dialevant),
                       MONTH(dialevant),
                       DAY(dialevant),
                       HOUR(horalevant),
                       MINUTE(horalevant),
                       0,
                       0) ASC

I hope it helps.

    
07.07.2016 / 06:58