The WEEKOFYEAR() function in MySQL is used to return the week number for a given date. The week starts from Sunday by default, and it considers the first week of the year to be the week containing January 1st. The week number is a value from 1 to 53.
Syntax
WEEKOFYEAR(date)
Parameters
date: The date for which you want to calculate the week of the year.
Example Usage
SELECT WEEKOFYEAR('2024-01-01') AS WeekNumber; -- Returns 1
SELECT WEEKOFYEAR('2024-12-31') AS WeekNumber; -- Returns 53
Notes
- Related Functions:
WEEK(): Offers more options for specifying week mode (start of week, year handling).YEARWEEK(): Combines year and week into a single value.
- The
WEEKOFYEAR()function is equivalent to usingWEEK(date, 3).
Let me know if you'd like more examples or explanations!
No comments:
Post a Comment