Page 1 of 1

Searching Dates

Posted: Wed Jan 19, 2005 7:34 am
by mohson
Im using this code to search my database for a particular date, this code worked fine when I was searching text i.e, names but when I search for dates it doesnt produce results even if I put in the exact copy of a date which I know exists.

Can anyone see where I am going wrong or give me any advice or another way to search dates in php.

Code: Select all

foreach($HTTP_POST_VARS as $varname => $value)
        $formVarsї$varname]=$value;

// the query used to search the DB
$query = "SELECT *, DATE_FORMAT(`dateoflastcontact`, '%d/%m/%y') 
AS `dateoflastcontact`, FROM `people` WHERE 'dateoflastcontact' LIKE '$formVarsїdateoflastcontact]%'";
$result = mysql_query($query);

Posted: Wed Jan 19, 2005 10:13 am
by feyd
it may be two things:

you're using single quotes instead of backticks in the WHERE clause's dateoflastcontact reference.. this may ask MySQL to check the string 'dateoflastcontact' instead of the column.. Not sure though.

you may need to use a date/time function on one or both of the values like TO_DAYS() if you want to match the date only, although if the value you are searching for is in the wrong format, then I don't know for sure.. as I haven't tested it personally.