Jump to content

Select MySQL MAX time


mo

Recommended Posts

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

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

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.