Jump to: navigation, search

Mysql YEARWEEK

From w3cyberlearnings

Contents

MySQL YEARWEEK Function

This function returns year and week of a date.

Syntax YEARWEEK

  • 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)
YEARWEEK(date);

Example 1

mysql> SELECT YEARWEEK('2012-05-24');
+------------------------+
| YEARWEEK('2012-05-24') |
+------------------------+
|                 201221 |
+------------------------+
1 row in set (0.00 sec)


Example 2

Only two Mondays for this input


mysql> SELECT YEARWEEK('2012-01-15',7);
+--------------------------+
| YEARWEEK('2012-01-15',7) |
+--------------------------+
|                   201202 |
+--------------------------+
1 row in set (0.00 sec)

Example 3

Three Sundays for this input


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

Related Links



Navigation
Web
SQL
MISC
References