|
Home > Archive > MySQL Server Forum > August 2005 > Selecting a Date range using CURDATE()
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Selecting a Date range using CURDATE()
|
|
| John Rappold 2005-08-10, 11:24 am |
| I've Googled this, but can't find an answer to my problem.
When a user selects a page with the recordset I want it to list dates that
fall into a certain range, related to CURDATE(). The range fields are
start_date and end_date, which are both DATETIME column types.
Using BETWEEN won't work because it won't list a date that starts BEFORE
CURDATE() e.g.
If CURDATE() is 2005-08-10
Then an event that has a start_date of 2005-08-06 and an end_date of
2005-08-26 won't show in the list, even though the date range does fall into
the CURDATE() of 2005-08-10.
Can someone help me with this? I hope I'm being clear as to what I need. It
is driving me crazy. :)
| |
| Gordon Burditt 2005-08-10, 11:24 am |
| >When a user selects a page with the recordset I want it to list dates that
>fall into a certain range, related to CURDATE(). The range fields are
>start_date and end_date, which are both DATETIME column types.
>
>Using BETWEEN won't work because it won't list a date that starts BEFORE
>CURDATE() e.g.
>
>If CURDATE() is 2005-08-10
>
>Then an event that has a start_date of 2005-08-06 and an end_date of
>2005-08-26 won't show in the list, even though the date range does fall into
>the CURDATE() of 2005-08-10.
>
>Can someone help me with this? I hope I'm being clear as to what I need. It
>is driving me crazy. :)
Ok, what's wrong with:
select * from table where curdate() >= start_date and
curdate() <= end_date;
I'm not sure why this doesn't also work:
select * from table where curdate() between start_date and end_date;
It seems to on some tables I have with dates in them. (Mysql 5.0.9, but
the specific version really shouldn't matter).
Gordon L. Burditt
|
|
|
|
|