Jump to content

[SOLVED] Comparing dates in query with BETWEEN


markkanning

Recommended Posts

Is anyone aware of a problem with MySQL 5.0+ with comparing dates in a query? I've got a query that works fine if I'm comparing dates/times inside of a single day, like this:

SELECT * FROM table WHERE NOW() BETWEEN '2007-09-21 03:00:00' AND '2007-09-21 15:00:00'

But if I compare 2 dates spanning a day, or multiple days, I get nothing.

 

Any thoughts?

 

Mark

Is anyone aware of a problem with MySQL 5.0+ with comparing dates in a query? I've got a query that works fine if I'm comparing dates/times inside of a single day, like this:

SELECT * FROM table WHERE NOW() BETWEEN '2007-09-21 03:00:00' AND '2007-09-21 15:00:00'

But if I compare 2 dates spanning a day, or multiple days, I get nothing.

 

Any thoughts?

 

Mark

be glad you get nothing or else MYSQL means error lol

u use now on your condtion right so its like having a range of 2007-09-21 03:00:00' to 2007-09-21 03:00:00'

i guess what you mean is

SELECT * FROM table WHERE FIELDHERE BETWEEN '2007-09-21 03:00:00' AND now()

 

Is anyone aware of a problem with MySQL 5.0+ with comparing dates in a query? I've got a query that works fine if I'm comparing dates/times inside of a single day, like this:

SELECT * FROM table WHERE NOW() BETWEEN '2007-09-21 03:00:00' AND '2007-09-21 15:00:00'

But if I compare 2 dates spanning a day, or multiple days, I get nothing.

 

Any thoughts?

 

Mark

 

In general, you would try to put your field value outside the "between", so that an index could be used...

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.