Searching Dates

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Searching Dates

Post 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);
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply