datetime - All MySQL records from yesterday -
what efficient way records datetime field falls somewhere between yesterday @ 00:00:00
, yesterday @ 23:59:59
?
table:
id created_at 1 2016-01-19 20:03:00 2 2016-01-19 11:12:05 3 2016-01-20 03:04:01
suppose yesterday 2016-01-19, in case i'd want return rows 1 , 2.
since you're looking date portion, can compare using mysql's date()
function. note if have large number of records can inefficient; indexing advantages lost derived value of date()
.
select * table date(created_at) = date(now() - interval 1 day);
Comments
Post a Comment