How to query mysql this week?

This is my request for the current day:

SELECT COUNT(*) FROM blog_posts WHERE postStatus = "pending" AND DATE(date_accepted) = CURDATE() 

Now what about if I want to request this week? Thanks in advance.

+6
source share
1 answer

Use the YEARWEEK() function

 WHERE YEARWEEK(date_accepted) = YEARWEEK(NOW()) 

Do not use WEEK() , because it will correspond to weeks from different years.

+12
source

Source: https://habr.com/ru/post/975711/


All Articles