How to Query Access Database Dates using PHP and MySQL

Posted on 2009-02-18
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

Question by:jasdak
    LVL 28

    Expert Comment

    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
    LVL 28

    Accepted Solution

    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

    Author Closing Comment

    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!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Suggested Solutions

    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now