Home  >  Article  >  Database  >  How to use the WEEK function in MySQL

How to use the WEEK function in MySQL

王林
王林forward
2023-05-28 13:46:061876browse

WEEK(date,index)

SELECT WEEK(‘2016-01-03') 
SELECT WEEK(‘2016-01-03', 0) 
SELECT WEEK(‘2016-01-03', 1)
-> 1 (该函数返回date在一年当中的第几周,date(01.03)是周日,默认是以为周日作为一周的第一天,函数在此处返回1可以有两种理解:1、第一周返回0,第二周返回1,.... ,2、以当年的完整周开始计数,第一周返回1,第二周返回2,... ,最后一周返回53)
-> 1 (week()默认index就是0. 所以结果同上)
-> 0 (当index为1时,表示一周的第一天是周一,所以,4号周一才是第二周的开始日)

The above is the detailed content of How to use the WEEK function in MySQL. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete