I have a table with 2 'datetime' fields: 'eventDate' and 'eventHour'. I'm trying to order by 'eventDate' and then by 'eventHour'.
For each date I will have a list os events, so that's why I will to order by date and then by time.
thanks!!
I'm not sure whether there's any hidden meaning in your question but the standard way of doing this seems to fit:
... order by eventDate, eventHour
That gives you hours within dates, like:
Feb 15
09:00
12:00
17:00
Feb 23
22:00
: :
If you actually have those two fields as real datetime
fields, your schema is screwed up. You should have a date
field for the date and a time
or integral field for the hour.
You could combine both into a single datetime
field but you should balance that against the inefficiencies of doing per-row functions in your select
statements if you want to separate them. It's usually better to keep fields separate if your going to use them distinctly.
If you do have to use per-row functions, you can use:
date(datetime_column)
time(datetime_column)
to extract just the date
and time
components of a datetime
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With