will35010 Posted August 9, 2010 Share Posted August 9, 2010 I'm using this query to return a count: SELECT COUNT(patientid) FROM event WHERE event = 'Registration' AND FROM_UNIXTIME(event_time) BETWEEN '$startdate' AND '$enddate'; It works fine unless the user selects the same date. the user has to select the day before and the day after the day that they actually want data for. How can I fix that? The date is being passed in YYYY-MM-DD format. Quote Link to comment https://forums.phpfreaks.com/topic/210213-query-help/ Share on other sites More sharing options...
bh Posted August 9, 2010 Share Posted August 9, 2010 SELECT COUNT(patientid) FROM event WHERE event = 'Registration' AND ((FROM_UNIXTIME(event_time) BETWEEN '$startdate' AND '$enddate') OR FROM_UNIXTIME(event_time) = '$startdate'); or SELECT COUNT(patientid) FROM event WHERE event = 'Registration' AND FROM_UNIXTIME(event_time) >= '$startdate' AND FROM_UNIXTIME(event_time) <= '$enddate'); Quote Link to comment https://forums.phpfreaks.com/topic/210213-query-help/#findComment-1096985 Share on other sites More sharing options...
will35010 Posted August 9, 2010 Author Share Posted August 9, 2010 SELECT COUNT(patientid) FROM event WHERE event = 'Registration' AND ((FROM_UNIXTIME(event_time) BETWEEN '$startdate' AND '$enddate') OR FROM_UNIXTIME(event_time) = '$startdate'); or SELECT COUNT(patientid) FROM event WHERE event = 'Registration' AND FROM_UNIXTIME(event_time) >= '$startdate' AND FROM_UNIXTIME(event_time) <= '$enddate'); Second query had an error. First query returned 0 for a single day picked. I think I'm just going to change my db to use date/time. It seems easier...lol. Thanks anyway. Quote Link to comment https://forums.phpfreaks.com/topic/210213-query-help/#findComment-1096990 Share on other sites More sharing options...
bh Posted August 9, 2010 Share Posted August 9, 2010 SELECT COUNT(patientid) FROM event WHERE event = 'Registration' AND FROM_UNIXTIME(event_time) >= '$startdate' AND FROM_UNIXTIME(event_time) <= '$enddate'; At the end of the second there was an unnecessary parenthesis. Quote Link to comment https://forums.phpfreaks.com/topic/210213-query-help/#findComment-1096995 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.