We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


How to Query Access Database Dates using PHP and MySQL

jasdak asked
Medium Priority
Last Modified: 2012-06-27
i have an access database i am connecting to using the below code.  when i use the below query to try to get rows with only a particular date i get no rows returned.  is there some difference in how access stores its date fields vs how mysql queries them?  and if so how do i fix this?

bottom line, how do i extract rows from an access database using php mysql odbc connector filtering using date criteria?

$odbc = odbc_connect ('DATABASE', 'username', 'pass') or die('Could    Not Connect to ODBC Database!');
$query = odbc_exec($odbc, "select * from Payments where EffDate = 2006-01-03") or die (odbc_errormsg());
//this one gives me data type mismatch 
//$query = odbc_exec($odbc, "select * from Payments where EffDate = '2006-01-03'") or die (odbc_errormsg());
//this one works fine but is not dates
//$query = odbc_exec($odbc, "SELECT * from Payments WHERE Custno = 652") or die (odbc_errormsg());
while($row = odbc_fetch_array($query))
	$running_balance = $running_balance + $row['Amount'];

Open in new window

Watch Question

There are 2 possible problems.

The first is that you need to use the US date format MM/DD/YYYY rather than YYYY-MM-DD though the latter should be OK.
The second is that the date field can also include the time so your sql needs to be

select * from Payments where EffDate >= '2006-01-03' AND EffDate < '2006-01-04'

Cheers, Andrew
Oh and it may need to be # around the dates rather than '

select * from Payments where EffDate >= #2006-01-03# AND EffDate < #2006-01-04#

Cheers, Andrew

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


thank you so much.  the pound sign on either side of the date fixed it all.  with quotes it was a type mismatch and without the quotes it would return zero results.  with the pound signs it works perfect.  Thanks!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.