Jump to content

MySQL Sorting Question


zebe

Recommended Posts

Hi,

I am writing a script that needs to sort by a field which contains a time value. I need to sort it in order of earlies to latest. The field type is a varchar. People have been putting in am/pm characters in this field as well and when I go to sort it comes out something like this:

8:45am
8:45am
8:45am
9:15am
9:30am
9:30am
9am
9am

In my query I have the following:
[code]ORDER BY REPLACE(bus_leaves_uri, ':', '')" [/code]

I was trying to take out the ":" thinking that was the problem with the ordering. Does anyone know a better mysql function that will actaully sort this type of data correctly?

Thanks for any help!


Link to comment
Share on other sites

decide on a new format and adjust the existing data for that...  I would say either use military time (1pm being 13:00) or having a seperate column to check am or pm.  Then you also want to check the input to make sure that people only enter valid times.  If its going to be a headache, make a dropdown for the hours then a dropdown for the minutes and combine them before submitting.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.