johram pong johram pong - 1 month ago 9
MySQL Question

fetch records from a field which is not in date time format

i have a varchar field name meeting_date which stores date like mm/dd/yyyy as in
12/25/2016 and now i try to fetch results from db where month and year match the meeting_date from a form request as below but i get no result

$y =$_REQUEST['y'];
$m =$_REQUEST['m'];
$date = "$y/$m";

$table = mysql_query("SELECT * FROM records WHERE meeting = 'Yes' AND (meeting_date LIKE '%".$date."%') ORDER BY id DESC");
$rows = mysql_fetch_assoc($table);


appreciate your time and help

Answer
meeting_date LIKE '%".$m."/%"."%/".$y."%'.

You have day between month and year.

It would be much better if you can change varchar field to date and format how it looks on site after query. Then your query would look like:

MONTH(meeting_date) = $m AND YEAR(meeting_date) = $y