WEEKOFYEAR()
This page is part of MariaDB's Documentation.
The parent of this page is: Functions for MariaDB Xpand
Topics on this page:
Overview
Returns the calendar-week number for a date.
USAGE
WEEKOFYEAR(date)
Argument Name | Description |
---|---|
| The date to evaluate |
DETAILS
WEEKOFYEAR()
is a date-time function that returns the week number in the range 1-53 for a given date.
The first day of the week is a Monday and first week of the year is one with 4 or more days in that year.
The return value is equivalent to calling WEEK(date, 3)
. See WEEK() for more details.
A NULL
is returned if the argument is NULL
.
EXAMPLES
SELECT WEEKOFYEAR('2020-02-01');
+--------------------------+
| WEEKOFYEAR('2020-02-01') |
+--------------------------+
| 5 |
+--------------------------+
SELECT WEEKOFYEAR('2020-01-02');
+--------------------------+
| WEEKOFYEAR('2020-01-02') |
+--------------------------+
| 1 |
+--------------------------+
CREATE TABLE day_list (
d DATE
);
INSERT INTO day_list VALUES
('2028-01-01'), ('2028-01-02'), ('2028-01-03'),
('2028-12-30'), ('2028-12-31'), ('2029-01-01');
SELECT d AS 'date',
DAYOFWEEK(d) AS DoW,
WEEKOFYEAR(d),
WEEK(d,3)
FROM day_list;
+------------+------+---------------+-----------+
| date | DoW | WEEKOFYEAR(d) | WEEK(d,3) |
+------------+------+---------------+-----------+
| 2028-01-01 | 7 | 52 | 52 |
| 2028-01-02 | 1 | 52 | 52 |
| 2028-01-03 | 2 | 1 | 1 |
| 2028-12-30 | 7 | 52 | 52 |
| 2028-12-31 | 1 | 52 | 52 |
| 2029-01-01 | 2 | 1 | 1 |
+------------+------+---------------+-----------+