MySQL WEEK() Function

MySQL | WEEK() Function: Learn about the WEEK() function, how it works, its usages, syntax, and examples.
Submitted by Apurva Mathur, on October 13, 2022

WEEK() Function

The WEEK() function is used to get the week number for the specified date. The value range of the function is 0-53.

WEEK() Syntax

SELECT week (date, mode[optional]);

WEEK() Parameter(s)

  • date: You have to provide the valid date on which you want to find the week number.
  • mode: This parameter is optional. This parameter specified the day on which the week starts.
    The following modes are present in this function:
    • 0 - First day of week is Sunday
    • 1 - First day of week is Monday and the first week of the year has more than 3 days
    • 2 - First day of week is Sunday
    • 3 - First day of week is Monday and the first week of the year has more than 3 days
    • 4 - First day of week is Sunday and the first week of the year has more than 3 days
    • 5 - First day of week is Monday
    • 6 - First day of week is Sunday and the first week of the year has more than 3 days
    • 7 - First day of week is Monday

WEEK() Return Value

The function returns the week number.

MySQL WEEK() Function Example 1

SELECT WEEK('1987-09-12');
Example 1: MySQL WEEK() Function

MySQL WEEK() Function Example 2

SELECT WEEK('2020-10-11');
Example 2: MySQL WEEK() Function



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.