Reputation: 499
I want to perform a query in MySql based on week number. The function I found ('WEEK()') gives me the week number for a certain date. However, I would like to use the week number as the date range, like this:
SELECT *
FROM x
WHERE price > 1
AND start_date_column between (start week 41 and end week 41)
Does anyone know of a function that could I could use to accomplish this?
Upvotes: 1
Views: 41
Reputation: 28834
There is WeekofYear()
function as well. It returns the calendar week of the date as a number in the range from 1 to 53. Sunday is considered as starting day of the week in this function. For eg:
SELECT WeekofYear('2018-10-18'); -- returns 42
You can do the following using the above-mentioned function:
SELECT *
FROM x
WHERE price > 1
AND WeekofYear(start_date) = 41
Even Week()
function would work as well, in the similar fashion:
SELECT *
FROM x
WHERE price > 1
AND Week(start_date) = 41
Upvotes: 2