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

Link to comment
Share on other sites

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()

 

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.