user3493797
user3493797

Reputation: 63

SQL Statement with the actual week

I have a table which look like this:

  Date       |    Day     |    Ingredients
-------------------------------------------
2014-08-20   | Wednesday  | Salt
2014-08-21   | Thursday   | Sugar
2014-08-22   | Friday     | Salt&Sugar
2014-08-28   | Thursday   | Salt

And I want to have only the dates there are in one week. Should I make an extra column 'Week' with the number of the week or is there a solution where I can set the beginning and the end of a week to only have the actual week. So I have all rows from the actual week.

SELECT * FROM table WHERE *`Date is in the actual week`*

Upvotes: 0

Views: 78

Answers (1)

xdazz
xdazz

Reputation: 160953

You mean to get the data of current week?

Use the YEARWEEK function.

SELECT * FROM your_table
WHERE YEARWEEK(`date`, 1) = YEARWEEK(CURRENT_DATE, 1)

Update: Use mode 1 if the beginning of week is Monday.

Upvotes: 2

Related Questions