Page 1 of 1

Want to WHERE just the date in a DATETIME data type.

Posted: Wed May 03, 2006 1:57 pm
by mattyboi
I have a sql query and I want to grab all the records in a table by the date. The problem is that the field with the date in it also has a time in it. It is a DATETIME data type.

Anyway ideas?

Matt

You can probably move this to the database section, just thought that I might have to format in PHP first before putting it in the SQL query.

Posted: Wed May 03, 2006 2:08 pm
by feyd

Posted: Wed May 03, 2006 2:25 pm
by mattyboi
It looks like that only works when you SELECT a date. I would like to do:

Code: Select all

$sales_rep = $_GET['sales_rep'];
$todays_date = date('Y-m-d');

$sql = "SELECT * FROM `client_leads` WHERE `SalesRep` = '$sales_rep' and `ApptDateTime` = '$todays_date'";
$result = mysql_query($sql);
The ApptDateTime is a DATETIME field.

Posted: Wed May 03, 2006 2:48 pm
by mattyboi
I got it, used a LIKE

Posted: Wed May 03, 2006 5:27 pm
by Burrito
better solution is to use the date() function mysql.

Code: Select all

SELECT * FROM `my_table` WHERE date(somedate) = '2006-03-05'