mo Posted March 12, 2009 Share Posted March 12, 2009 I have a MySQL table where I have a time stamp in 24 hour format and I am trying to formulate a query where I can select the latest time. I could select the records and process the greatest time in PHP code but I want to do it all in one shot in a query. The issue is that my target field `close_time` holds time in 24hr format and that if I have 10PM (22:00:00) and 2AM (02:00:00), 10PM comes back as the later time. Any help will be appreciated. Query is like the following: SELECT MAX(`close_time`) as close FROM mytable WHERE day_of_week = 6; Link to comment https://forums.phpfreaks.com/topic/149133-select-mysql-max-time/ Share on other sites More sharing options...
rhodesa Posted March 12, 2009 Share Posted March 12, 2009 uh...10PM is later then 2AM Link to comment https://forums.phpfreaks.com/topic/149133-select-mysql-max-time/#findComment-783078 Share on other sites More sharing options...
lonewolf217 Posted March 12, 2009 Share Posted March 12, 2009 you would need another quantifier other than time, i.e. date to sort it properly it sounds like. If you are filtering by your current SQL query where you limit the results to a single day of the week, then as rhodesa said, 10PM is later than 2AM so its working properly Link to comment https://forums.phpfreaks.com/topic/149133-select-mysql-max-time/#findComment-783080 Share on other sites More sharing options...
mo Posted March 12, 2009 Author Share Posted March 12, 2009 you would need another quantifier other than time, i.e. date to sort it properly it sounds like. If you are filtering by your current SQL query where you limit the results to a single day of the week, then as rhodesa said, 10PM is later than 2AM so its working properly Yes, I know 10PM is later but in the way I want to use the result set, 2AM should be later. 2AM is a store close time. I am building a time range drop down box and and I have several stores with different open and close hours. I can get the earliest open hour from the list of stores but I need the latest close hour. In PHP I could use strtotime to get the lastest time but I want to do this in a query. My table only has store ID, day of the week, open hour and close hour. The query would specify the day of the week, so I guess I need to get the later time in PHP versus the query? Link to comment https://forums.phpfreaks.com/topic/149133-select-mysql-max-time/#findComment-783085 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.