Hello,

I currently have a table with a "completed" DATETIME field. I am trying to run a query that will return all rows *inclusive* of the start and end dates. I have tried the following query:

SELECT `name`, `completed` FROM `table` WHERE `completed` BETWEEN '2004-07-21' AND '2004-07-23';

The problem is that this query will only return rows from 2004-07-22, and does not include rows from 2004-07-21 or 2004-07-23, like I need it to. This could be the desired behavior for the BETWEEN operator (I couldn't seem to find any documentation of it in the documents for some reason), so I also tried:

SELECT `name`, `completed` FROM `table` WHERE `completed` >= '2004-07-21' AND `completed` <= '2004-07-23';

This does the same thing, it only returns dates from 2004-07-22 without including the start or end date.

I have tried adding a time (e.g. 2004-07-21 00:00:00 and 2004-07-23 23:59:59), but again, only 2004-07-22 is returned.

If I remove one of the conditions, I get the correct result.  e.g.:

SELECT `name`, `completed` FROM `table` WHERE `completed` >= '2004-07-21';

Will return all rows on *and* after 2004-07-21, as desired. But with both operators, it does not work.

I have tried this query on both 3.23.58 and 4.0.17. I searched the net over and could not find a definitive answer to this problem, so apologies if it's been answered before.

TIA,

Jeremy Brown


-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to