Syntax
Parameters
-
Date: The supported data types are DATETIME and DATE. -
Mode: optional. The supported data type is INT. This parameter is used to specify the logic for calculating the week number, that is, whether the week starts on Sunday or Monday, and whether the return value is in the range of 0–53 or 1–53. Value range: 0–7. Default value:0. If this parameter is not specified, mode0is used by default. The following table describes how this parameter works.
Return value
Returns a value of the INT type. Value range: 0–53. The specific range is determined based on themode parameter. NULL is returned if the value of date is invalid or the input value is empty.
Examples
Calculate the week number for2007-01-01. 2007-01-01 is Monday on the calendar.
Modeis set to0and0is returned. The week starts on Sunday.2007-01-01is Monday and cannot be week 1. Therefore,0is returned.
Modeis set to1and1is returned. The week starts on Monday and2007-01-01is Monday.
Modeis set to2and53is returned. The week starts on Sunday. However,2007-01-01is Monday and the value range is 1–53. Therefore,53is returned, indicating that this is the last week of the previous year.