Jake
Jake

Reputation: 3486

MYSQL get rows inserted from today

I have the following code which keeps displaying 0 although rows are being inserted every day, i need it to work so that it finds what has been added today.

SELECT count(distinct id) AS today 
 FROM exchange 
 WHERE time >= date_sub(now(), interval 0 day)

Thanks

today means any time after 00:00 and format is: time();

Upvotes: 1

Views: 2692

Answers (2)

Hashim Aziz
Hashim Aziz

Reputation: 6092

This seems to work in the same way as the CURDATE solution, by starting a day from 12:00 AM midnight rather than the first 24 hours:

select count(*) from <table> where date(<date_column>)=date(now());

Upvotes: 0

ypercubeᵀᴹ
ypercubeᵀᴹ

Reputation: 115550

I guess that `time` is a timestamp column and id is the Primary Key of the table (so no need to count distinct ids, just count rows):

SELECT count(*) AS today 
FROM exchange 
WHERE `time` >= CURDATE()

Upvotes: 4

Related Questions