user198989
user198989

Reputation: 4663

Fetch rows only from specific date in mySQL

I am trying to fetch rows only from specific date (like today, yesterday or 2 days ago) in mySQL. I have a column named "date" in my rows. (which includes dates like 1365053426).

$result=mysql_query("SELECT count(*) as total from track WHERE `date` >= CURRENT_DATE
  AND `date`  < CURRENT_DATE + INTERVAL 1 DAY");

I have tried this query, but it returns "0". What is the correct way to do that ?

Upvotes: 0

Views: 146

Answers (2)

John Woo
John Woo

Reputation: 263933

how about using BETWEEN?

SELECT COUNT(*) as TotalCount
FROM   Track
WHERE  Date BETWEEN CURDATE() + INTERVAL -2 DAY AND CURDATE()

Upvotes: 2

Jhonathan H.
Jhonathan H.

Reputation: 2713

How about using datediff() function?

SELECT count(*) as total from track WHERE datediff(now(),date)=interval day

note: interval day could be declare from 0 -> up depends on what previous date you want to show

Upvotes: 1

Related Questions