Pick up the records for the current week

0

I have a system where the user registers the information in a Mysql database. One of the fields is DataCadastro of type Date () and it is only registered from Monday to Friday, that is, on the days that the company of that user works. I just have to get the records for the current week. I understand that to get the next 7 days, I have to do this:

SELECT * FROM tabela WHERE dataCadastro BETWEEN CURRENT_DATE()-7 AND CURRENT_DATE()

But how would I go about getting only the current week's dates?

    
asked by anonymous 24.07.2018 / 15:54

1 answer

2

Solution 1:

Because it is MySQL, you can use the YEARWEEK ( ) , just put the date inside the function YEARWEEK('2018-07-24')

SELECT * FROM your_table WHERE YEARWEEK('date', 1) = YEARWEEK(CURDATE(), 1)

Solution 2:

SELECT * FROM items WHERE created_at > DATE_SUB(NOW(), INTERVAL 1 WEEK);
    
24.07.2018 / 16:02