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

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
mattyboi
Forum Commoner
Posts: 34
Joined: Mon Feb 06, 2006 9:42 pm

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

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

Post by feyd »

mattyboi
Forum Commoner
Posts: 34
Joined: Mon Feb 06, 2006 9:42 pm

Post 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.
mattyboi
Forum Commoner
Posts: 34
Joined: Mon Feb 06, 2006 9:42 pm

Post by mattyboi »

I got it, used a LIKE
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

better solution is to use the date() function mysql.

Code: Select all

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