date(now) only working with time 00:00:00

时间:2016-04-25 09:27:41

标签: php mysql date

I'm trying to get the number of rows where the date is today. Its working like this but only if the time is 00:00:00 so if i change the time to for example 2016-04-25 05:30:30 its not counting that row for some reason.

$result16  = $dbhandle->query("SELECT * FROM email  WHERE signoff = DATE(NOW() )");
$row_cnt16 = $result16->num_rows;

What should I do to fix this?

Table information:
signoff = varchar(250)

Outputs:

if date is 2016-04-25 00:00:00 the output is 2

if the date is 2016-04-25 05:04:00 output is 1

3 个答案:

答案 0 :(得分:2)

try this:

SELECT *
FROM email 
WHERE signoff BETWEEN DATE(NOW()) AND  DATE(NOW() + INTERVAL 1 DAY)

答案 1 :(得分:1)

First change your data type of signoff to datetime.

Then use this query

SELECT * FROM email  
WHERE date(signoff) = DATE(CURDATE())

If speed is an issue you can use

SELECT * FROM email  
WHERE signoff >= curdate()
  AND signoff < curdate() + interval 1 day

答案 2 :(得分:1)

Try this by adding Date to the signoff

$result16 = $dbhandle->query("SELECT * FROM email  WHERE DATE(signoff) = DATE(NOW() )");