mikefrederick Posted March 17, 2008 Share Posted March 17, 2008 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? Quote Link to comment Share on other sites More sharing options...
papaface Posted March 17, 2008 Share Posted March 17, 2008 does order by desc or order by asc in your SQL make a difference? Quote Link to comment Share on other sites More sharing options...
mikefrederick Posted March 17, 2008 Author Share Posted March 17, 2008 sure, it will reverse the order but it does not make the field sensitive to am or pm. Quote Link to comment Share on other sites More sharing options...
mikefrederick Posted March 17, 2008 Author Share Posted March 17, 2008 anyone? Quote Link to comment Share on other sites More sharing options...
lemmin Posted March 17, 2008 Share Posted March 17, 2008 I assume that the field is not in a date/time format? Is it an option to change the formatting of the field? Quote Link to comment Share on other sites More sharing options...
Jeremysr Posted March 17, 2008 Share Posted March 17, 2008 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. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 17, 2008 Share Posted March 17, 2008 To do this the proper way, you need a TIME type field and then format the field in your select query the way you want to output it using the mysql TIME_FORMAT() function. Quote Link to comment Share on other sites More sharing options...
schilly Posted March 17, 2008 Share Posted March 17, 2008 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() ). Quote Link to comment Share on other sites More sharing options...
mikefrederick Posted March 17, 2008 Author Share Posted March 17, 2008 why doesnt this work? $getdates=mysql_query("select *, time_format(timestart),'%g:%i %a') as date_f from events order by date_f asc"); Quote Link to comment Share on other sites More sharing options...
Jeremysr Posted March 17, 2008 Share Posted March 17, 2008 It looks like you don't have enough parentheses. Quote Link to comment Share on other sites More sharing options...
mikefrederick Posted March 17, 2008 Author Share Posted March 17, 2008 minus the ) in the timestart() Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 17, 2008 Share Posted March 17, 2008 ORDER BY the TIME field timestart. Using ORDER BY the formatted date_f is right back where you started. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.