Skip to content

WEEK()

Function Description

Used to calculate the number of weeks for a given date. This function returns an integer representing the number of weeks in which the specified date is. If date is NULL, NULL is returned.

Function Syntax

> WEEK(date)

Parameter definition

Parameters Description
date Required parameters. Indicates the date to calculate the number of weeks. MatrixOne defaults to the start of the week as Monday, and the return value ranges from 0 to 53.

Example

  • Example 1:
mysql> SELECT WEEK('2008-02-20');
+------------------------+
| week(2008-02-20) |
+------------------------+
| 8 |
+------------------------+
1 row in set (0.01 sec)
  • Example 2:
drop table if exists t1;
CREATE TABLE t1(c1 DATETIME NOT NULL);
INSERT INTO t1 VALUES('2000-01-01');
INSERT INTO t1 VALUES('1999-12-31');
INSERT INTO t1 VALUES('2000-01-01');
INSERT INTO t1 VALUES('2006-12-25');
INSERT INTO t1 VALUES('2008-02-29');

mysql> SELECT WEEK(c1) FROM t1;
+-------------+
| week(c1) |
+-------------+
| 52 |
| 52 |
| 52 |
| 52 |
| 9 |
+-------------+
5 rows in set (0.00 sec)

limit

MatrixOne's WEEK() function only supports the date parameter, and does not support the optional parameter [, mode], which is different from MySQL.