I have a variable called $date with a date format like 2012-01-30. On the other hand I have a field called srt_date_sortie in a mysql table. The format of that field is like 2012-01-30 11:31:00. I would like to select all records where $date and srt_date_sortie have equal dates not taking into consideration the time. Hope someone can help.
mysql_query("SELECT * FROM sorties WHERE srt_date_sortie = '$date'");
Here below how I build $date :
++$input;
$test=$input." days";
$date=date('Y-m-d', strtotime($test));
Thank you in advance for your replies. Cheers. Marc
For performance reasons you should avoid comparing against a derived column like
DATE(srt_date_sortie)as this will prevent any indexes from being used. This negates a few of the solutions already posted.The most efficient way of querying against your
DATETIMEfield is by using a range query like:Unless you need all of the rows from the table the
SELECT *could be inefficient, just list the rows that you need to retrieve.