MySQL YEARWEEK() Function

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

YEARWEEK() Function

The YEARWEEK() function is used to get the year and the week number. The range for the week number is 0 to 53.

YEARWEEK() Syntax

SELECT YEARWEEK('date','mode[optional]');

YEARWEEK() Parameter(s)

The function accepts the two parameters, they are -

  • date: You have to provide the valid date on which this function will fetch the year and week numbers.
  • 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

YEARWEEK() Return Value

This function returns the year and the week number.

MySQL YEARWEEK() Function Example 1

SELECT YEARWEEK('1987-10-11');
Example 1: MySQL YEARWEEK() Function

Here 1987 is the year and 41 is the week number.

MySQL YEARWEEK() Function Example 2

SELECT YEARWEEK('2020-01-11');
Example 2: MySQL YEARWEEK() Function

In this example, 2020 is the year and 01 is the week number.




Comments and Discussions!

Load comments ↻





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