Jump to content

query help


will35010

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/210213-query-help/
Share on other sites

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');

Link to comment
https://forums.phpfreaks.com/topic/210213-query-help/#findComment-1096985
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/210213-query-help/#findComment-1096990
Share on other sites

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.