Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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