目錄
- 1.dayofweek函數
- 2.weekday函數
- 3.weekofyear函數
1.dayofweek函數
功能:統計某天為星期幾
dayofweek(date) - Returns the day of the week for date/timestamp (1 = Sunday, 2 = Monday, ..., 7 = Saturday).
dayofweek返回值為:1-7,1 = 星期日, 2 = 星期一, …, 7 = 星期六,從星期日開始
示例:
SELECT dayofweek('2025-07-15'); ---3(星期二)
2.weekday函數
功能:統計某天為星期幾
weekday(date) - Returns the day of the week for date/timestamp (0 = Monday, 1 = Tuesday, ..., 6 = Sunday).
weekday返回值為:0-6,0 = 星期一, 1 = 星期二, …, 6= 星期日,從星期一開始
示例:
select weekday('2025-07-15'); ---1(星期二)
3.weekofyear函數
功能統計:某天為某年的第幾周
weekofyear(date) - Returns the week of the year of the given date. A week is considered to start on a Monday and week 1 is the first week with >3 days.
select weekofyear('2025-07-15') --29