Use today
where date(`entry_date`) = curdate()
This month
where month(`entry_date`) = month(curdate()) and year(`entry_date`) = year(curdate())
this week
WHERE `entry_date` BETWEEN (CURDATE() - Interval DAYOFWEEK(CURDATE()) day) AND (CURDATE() - Interval DAYOFWEEK(CURDATE()) day + Interval 1 week)
The above query is helpful for understanding. But this is not very good for performance. See the following. This is much better.
SET @s:=(CURDATE() - Interval DAYOFWEEK(CURDATE()) day) SET @e:=(CURDATE() - Interval DAYOFWEEK(CURDATE()) day + Interval 1 week) SELECT .... WHERE `entry_date` BETWEEN @s AND @e
Here, the DAYOFWEEK function returns an integer starting with 1 = Sunday. Thus, your weeks will be considered Saturday as the start date. If you want Monday add + Interval 2 day at intervals.
This can also be simplified as follows. But he does not support a single day, like the first day of the week. Thus, it is not tolerated for the whole culture.
where yearweek(`entry_date`) = yearweek(curdate())
Shiplu mokaddim
source share