Jump to content

order by question with time


mikefrederick

Recommended Posts

i have a field in a table that contains times of the day in the format 11:00 am, 10:20 pm, etc. If I order by that field, then the pm dates will still come up before the am ones. For example, since 10:20 is less than 11 it will come before 11, but I need it to come after since it is actually later in the day. Is there anyway to do this without breaking the am/pm part into another field?

Link to comment
Share on other sites

That seems like something impossible to do in SQL, but I'm not sure.

 

It's a good idea to store data in ways that a computer can work with better. I think you should store it as 24-hour time, or even as a number representing the number of seconds past midnight. Then when displaying it on the screen, you can format better it for a human to read.

Link to comment
Share on other sites

sounds like a string field. if you are storing time, either use the sql time field or store it as an int using the unix timestamp. I always use the unix timestamp( time() ) then format it in php after( date("date string",time() ).

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.