Jump to content

Query by date range


dk4210

Recommended Posts

Hello Guys,

 

I have a question.. I am trying to query the data base for a specific date range but it's not displaying the correct date range..

 

Here is my query

SELECT * FROM report WHERE start_date AND end_date BETWEEN '2011-08-01 00:00:00' AND '2011-08-31 00:00:00'

 

It seems to be loading all the rows not just the date rage specified above.. Please advise..

 

Thanks, Dan

Link to comment
https://forums.phpfreaks.com/topic/248179-query-by-date-range/
Share on other sites

On more question for ya..

Is there a way to construct a query to grab the date range about and combine it with another table for example if I had two tables

 

Table A

|id |listing_id| start_date | end_date|

 

 

Table B

| listing id | listing_name |

 

 

What I would like to do is query table A for * with start and end date and get the id

 

Create a second query to grab the listing name in table b

 

Combine the query results  to show is the listing name in the csv file that I will be exporting...

 

Did I lose you?

 

Thanks for your help..

 

 

Link to comment
https://forums.phpfreaks.com/topic/248179-query-by-date-range/#findComment-1274405
Share on other sites

Never use queries in a loop, always use a JOIN.

 

SELECT table_b.listing_id, listing_name, start_date, end_date
FROM Table_a
join table_b on table_a.listing_id = table_b.listing_id
WHERE (start_date BETWEEN '2011-08-01 00:00:00' AND '2011-08-31 00:00:00') AND (end_date BETWEEN '2011-08-01 00:00:00' AND '2011-08-31 00:00:00')

-Dan

Link to comment
https://forums.phpfreaks.com/topic/248179-query-by-date-range/#findComment-1274433
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.