From: René Fournier [mailto:[EMAIL PROTECTED] 

> I'm trying to count rows that were added today. The column that I am 
> counting on is in DATETIME format, so there are hours and minutes and 
> seconds recorded, but I only need to check the date....
> 
> $sql =        "SELECT
>                       COUNT(table.id)
>               FROM table
>               WHERE table.created = NOW()";
> 
> $num = mysql_result(mysql_query($sql),0);
> 
> The problem with this is that unless the record was added at 
> precisely the same time as NOW()-which never happens-no rows are 
> returned. Is there a way I can round off table.created to just a 
> DATE, then compare it to CURDATE()??  I've been reading DATE 
> Format functions, but am not sure how to proceed.
> 
> Thanks in advance.

Try this:

SELECT COUNT(table.id) 
FROM table
WHERE DATE_FORMAT(table.created, '%Y-%m-%d') = CURDATE();

Should do what you're looking for. HTH!


-- 
Mike Johnson             Smarter Living, Inc.
Web Developer            www.smartertravel.com
[EMAIL PROTECTED]   (617) 886-5539

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to