JSHINER Posted June 24, 2008 Share Posted June 24, 2008 Wondering how I can get a query to return results between two times. For the times I have: $timeNow = time(); $startDate = time($page['query']['$start_date']); $endDate = time($page['query']['$end_date']); I want it to return results where $startDate > $timeNow < $endDate But my first problem is all of those are display the same time (current time) - and then, how do I setup a query to that effect. Link to comment https://forums.phpfreaks.com/topic/111686-solved-quick-question-about-dates-time/ Share on other sites More sharing options...
lemmin Posted June 24, 2008 Share Posted June 24, 2008 Did you solve this? If not, the field you are comparing obviously has to be in DATE/TIME format then you can compare as you would expect: "SELECT * FROM Table WHERE aDate > NOW() AND aDate < '$endDate'" $endDate has to be a string in a date/time format. I think that a bunch work; one is "mm/dd/yyyy" and I think "yyyy-mm-dd" works also, and both probably work with only digit years. Link to comment https://forums.phpfreaks.com/topic/111686-solved-quick-question-about-dates-time/#findComment-573297 Share on other sites More sharing options...
PFMaBiSmAd Posted June 24, 2008 Share Posted June 24, 2008 Greater-than/less-than comparisons using "mm/dd/yyyy" do not work. Link to comment https://forums.phpfreaks.com/topic/111686-solved-quick-question-about-dates-time/#findComment-573306 Share on other sites More sharing options...
lemmin Posted June 24, 2008 Share Posted June 24, 2008 Really? I know it doesn't work in Access but I swear I had tried it in MySQL. Sorry if I'm mistaken. In that case, I guess you would have to use the DATEDIFF() function: "SELECT * FROM Table WHERE DATEDIFF(aDate, NOW()) > 0 AND DATEDIFF(aDate, '$endDate') < 0"; Link to comment https://forums.phpfreaks.com/topic/111686-solved-quick-question-about-dates-time/#findComment-573339 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.