大数据之Hive:Hive中week相关的几个函数

目录

1.dayofweek函数

功能:统计某天为星期几

powershell 复制代码
dayofweek(date) - Returns the day of the week for date/timestamp (1 = Sunday, 2 = Monday, ..., 7 = Saturday).

dayofweek返回值为:1-7,1 = 星期日, 2 = 星期一, ..., 7 = 星期六,从星期日开始

示例:

sql 复制代码
SELECT dayofweek('2025-07-15');  ---3(星期二)

2.weekday函数

功能:统计某天为星期几

powershell 复制代码
weekday(date) - Returns the day of the week for date/timestamp (0 = Monday, 1 = Tuesday, ..., 6 = Sunday).

weekday返回值为:0-6,0 = 星期一, 1 = 星期二, ..., 6= 星期日,从星期一开始

示例:

sql 复制代码
select weekday('2025-07-15');  ---1(星期二)

3.weekofyear函数

功能统计:某天为某年的第几周

powershell 复制代码
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.
sql 复制代码
select weekofyear('2025-07-15') --29