johram pong johram pong - 3 years ago 124
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 Source
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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download