Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gman01's avatar

OrderBy Date & Time

Hi, I have a database that has 2 columns, date_of_callback, time_of_callback

date_of_callback = 2018-02-22 time_of_callback = 4:30pm

I seem to get the date_of_callback in order, but the time_of_callback can be anytimes, what would be the best way to sort by date and then time?

            $clients =  Client::orderBy('date_of_callback', 'ASC')
                ->orderBy('time_of_callback', 'ASC')
                ->where('lead_status', 'LIKE', "%Callback%")
                ->paginate(15);

        }

0 likes
1 reply
Helmchen's avatar

4:30pm would probably be interpreted as string so the sorting may not be what you want (cpt. obvious i know^^)

MySQL has an TIME type/column or you can use the combined DATETIME type

if thats no option for you - just use an integer field and convert the time values to seconds - both ways should give you better results

Please or to participate in this conversation.