Re: SQL Question: Search Records between two dates.
| From: | Ernest E Vogelsinger | Date: | Wed, 11 Dec 2002 00:15:59 +0000 |
| Subject: | Re: SQL Question: Search Records between two dates. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-127739@lists.php.net to get a copy of this message | ||
select * from table_name where (start_date >='2002-10-01' and start_date
<='2002-12-10') or (end_date >='2002-10-01' and end_date
<='2002-12-10')
At 01:08 11.12.2002, [-^-!-%- said:
--------------------[snip]--------------------
>
>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.
>
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
--------------------[snip]--------------------
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/