SQL Question: Search Records between two dates.

From: Date: Wed, 11 Dec 2002 00:08:48 +0000
Subject: SQL Question: Search Records between two dates.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-127738@lists.php.net to get a copy of this message
Hello everyone, I need to get a recordset between two dates, and am having a little trouble. I was wondering if someone could me make it more efficient. The goal: Each record has a start_date and end_date field. I want to be able to extract records that has the start_date and/or end_date, within the specified date range. What I have: select * from table_name where start_date >='2002-10-01' and end_date <='2002-12-10' ... This works, but is somewhat inconsistent. Example: 1) the query will exclude a record that has an end_date later then 12/10, but a start_date later then 10/01. *** I need it to include that*** 2) The query also list records with a january 2003 end_date. i.e. end_date=2003-01-15. Strange. I've read about the mysql BETWEEN and DATE DIFF function, but don't fully get it. I'm hoping that someone can help clarifying it. Is there a better way to do this? Am I missing something? Please help. -john =P e p i e D e s i g n s www.pepiedesigns.com Providing Solutions That Increase Productivity Web Developement. Database. Hosting. Multimedia.

« previous php.general (#127738) next »