Jump to content

[SOLVED] select where now() between start and end


bschultz

Recommended Posts

This query isn't returning what I thought it would...

 

$sql = "SELECT * FROM content WHERE NOW() BETWEEN startdate AND enddate";

 

Both startdate and enddate are datetime formats in the db.  What is the correct syntax for this query?

 

Thanks.

Link to comment
Share on other sites

Well you said there are no errors and it's returning results, just that some of them have expired enddates.

 

The only thing I can think of is NOW() is not what you're expecting it to be, which means the clock on that machine may be wrong.

 

Try this:

$sql = "SELECT *, now() as thenow FROM content WHERE NOW() BETWEEN startdate AND enddate";

Link to comment
Share on other sites

Thanks for the help!

 

The server time is correct...just checked it.

 

Your code still displayed expired results.

 

The one record that's displaying wrong (the only one that's expired) has this:

 

2009-05-29 17:00:00

 

as it's enddate value.

 

 

As you can see on this page (http://www.kkbj.com/datetime.php) the time is right...and the enddate field in the db is before the current time.

Link to comment
Share on other sites

All is working now.  I had changed the field type from date to datetime, and thought it was working...until it kept displaying the outdated entries.  I deleted the table and started over (with datetime as the field types), and now it's working just fine.

 

Thanks.

 

 

 

 

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.