Jump to: navigation, search

Mysql WEEK

From w3cyberlearnings

Contents

MySQL WEEK Function

This function returns the week number for date. With the second argument, it specifies whether the week stars on Sunday or Monday. It returns should be in the range from 0 to 53, or 1 to 53. When the mode is not included, the default_week_format will be used.

Syntax WEEK

  • date: date input
  • mode (optional)
    • mode:0 for Sunday, and range 0-53 (with a Sunday in this year)
    • mode:1 for Monday, and range 0-53 (with more than 3 days this year)
    • mode:2 for Sunday, and range 1-53 (with a Sunday in this year)
    • mode:3 for Monday, and range 1-53 (with more than 3 days this year)
    • mode:4 for Sunday, and range 0-53 (with more than 3 days this year)
    • mode:5 for Monday, and range 0-53 (with a Monday in this year)
    • mode:6 for Sunday, and range 1-53 (with more than 3 days this year)
    • mode:7 for Monday, and range 1-53 (with a Monday in this year)
WEEK();

Example 1

mysql> SELECT WEEK('2012-01-15',6);
+----------------------+
| WEEK('2012-01-15',6) |
+----------------------+
|                    3 |
+----------------------+
1 row in set (0.00 sec)

Example 2

mysql> SELECT WEEK('2012-01-31');
+--------------------+
| WEEK('2012-01-31') |
+--------------------+
|                  5 |
+--------------------+
1 row in set (0.00 sec)

Related Links



Navigation
Web
SQL
MISC
References