Jump to content

query MySQL with date BETWEEN this and that not working


Recommended Posts

Hi I am trying to ask MySQL for records that fall between dates like this:

 

$FromDate='2008-01-01';
$ToDate='2008-02-15';

$query="SELECT * FROM orders WHERE datepaid BETWEEN $FromDate and $ToDate";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
echo '<br>The resulting rows were '.$num.'<br>';

 

And I made sure there were dates in the database that do fall within that range.

And the table field called "datepaid" is a "date" field in MySQL, not just a text field

 

But I still come up with zero rows returned.

 

I looked to see if there was a known bug for the BETWEEN statement and also tried

WHERE  datepaid>$FromDate and datepaid<$ToDate

 

but that didn't work either.

 

 

Any help is much appreciated!!!!!!!

Thank you in advance.

 

 

 

 

You forgot the quotes around the date values:

 

$query="SELECT * FROM orders WHERE datepaid BETWEEN '$FromDate' and '$ToDate'";

 

Always check for any possible errors after a query, and before executing any subsequent commands (like mysql_num_rows). If you had, it would have indicated to you the syntax problem in your query.

 

Good luck.

 

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.