I’ve got a bunch of rows with a field called “title” who’s data looks like this:
Friday 8:00AM - Hunter Arena 2
Wednesday 7:30AM - West Grass Field
Thursday 8:00AM - Hunter Arena 1
Saturday 8:00AM - Hunter Arena 1
Wednesday 8:00AM - Hunter Arena 2
I’m looking to order by the day in the week. (Which I assume would involve parsing the string and then doing some sort of date sort) Is this possible with a MYSQL query?
Thanks in advance
-J
One option is to creating a holding table (temp, permanent, your choice!) of some kind of your weekdays and their sort weight.
Then you could extract the first word from your column (i.e. find the day of week), and JOIN the holding/reference table of weekday sort weights.
It’s much more preferable to actually have a
datetimecolumn to be able to naturally sort by.Another alternative: you could achieve this another way by creating a user-defined function who could do the same. You could then, with dubious performance, call the UDF in your
ORDER BY. The function would find/refer to the weight of the weekday.