未经允许,禁止转载,一经发现,必定严究
HIVE
HIVE系统自带函数290个,日期类函数27个
show functions查看系统函数
HIVE 日期函数
1)unix_timestamp
返回当前时间或指定时间的时间戳
select unix_timestamp();

2)from_unixtime
转换时间戳到当前时区的时间格式
select from_unixtime(1666541487);
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-oz6uWBpU-1666627188514)(C:\Users\31505\AppData\Roaming\Typora\typora-user-images\1666541574130.png)]](/https://i-blog.csdnimg.cn/blog_migrate/3d0cc354ca7c921861258cfe6c8a9cc0.png)
3)current_date
查看当前日期(不包括时间)
select current_date();
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-g4F8HKF0-1666627188514)(C:\Users\31505\AppData\Roaming\Typora\typora-user-images\1666541621415.png)]](/https://i-blog.csdnimg.cn/blog_migrate/db8c9741e5ba28d9e85d9d5bf50f3a2f.png)
4)to_date
返回当前日期(不包括时间)
select to_date('2022-10-24 10:03:01');

5)current_timestamp
查看当前时间(包括日期),精确到毫秒
select `current_timestamp`();

6)year
获取日期中的年份
select year('2020-02-02');

7)month
获取日期中的月份
select month('2020-02-02');

8)day
获取日期中的日
select day('2020-02-02');
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-BVLgofVq-1666627188515)(C:\Users\31505\AppData\Roaming\Typora\typora-user-images\1666625691566.png)]](/https://i-blog.csdnimg.cn/blog_migrate/d7d34cbbc04bb2bc3dc854c2ea2564ad.png)
9)hour
获取日期中的小时
select hour('2020-02-02 13:12:56');

10)minute
获取日期中的分钟
select minute('2020-02-02 13:12:56');

11)second
获取日期中的秒
select second('2020-02-02 13:12:56');

12)weekofyear
返回当前日期是一年中的第几周
select weekofyear('2020-02-02 13:12:56');

13)dayofmonth
返回当前日期是一个月中的第几天
select dayofmonth('2020-02-02 13:12:56');

14)dayofweek
返回当前日期是星期几
select dayofweek('2020-02-02 13:12:56');

15)last_day
返回当前月的最后一天
select last_day('2020-02-02 13:12:56');

16)datediff
返回两个日期相隔的天数(结束日期减去开始时间)
select datediff('2020-07-02','2020-04-23');
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-V3fEKwuO-1666627188517)(C:\Users\31505\AppData\Roaming\Typora\typora-user-images\1666626150498.png)]](/https://i-blog.csdnimg.cn/blog_migrate/df5e70530a744fa5d1cba5de51252ac0.png)
17)months_between
返回两个日期相差的月份
select months_between('2020-07-02','2020-04-23');

18)date_add
返回日期增加 days 天后的日期
select date_add('2020-07-02',20);

19)date_sub
返回日期减去 days 天后的日期
select date_sub('2020-07-02',20);

20)date_format
将日期解析为指定格式的字符串
select date_format('2020-02-02 13-12-56','yyyy/MM/dd HH:mm:ss');

21)add_months
返回当前日期加 months 个月后的日期
select add_months('2020-02-02 13-12-56',2);

22)next_day
获取当前日期所在本周,返回本周星期N的日期
select next_day('2022-10-24','SU'); --获取2022-10-24所在周星期日的日期

23)trunc
返回时间最开始的年份或月份
select trunc('2022-10-24','YYYY'); --时间最开始的年份
select trunc('2022-10-24','MM'); --时间最开始的月份

24)quarter
返回当前日期的季度
select quarter('2020-02-02');

HIVE 合集
1、hive 操作语句–DDL篇
2、hive 操作语句–DML篇
3、hive 函数汇总–开窗函数篇
4、hive 函数汇总–日期函数篇
博客主要介绍了HIVE系统的日期函数,包括unix_timestamp、from_unixtime等24个函数的功能,如获取时间戳、转换时间格式、获取日期各部分信息等。还提及了HIVE合集,包含操作语句的DDL、DML篇以及函数汇总的开窗函数、日期函数篇。

1万+

被折叠的 条评论
为什么被折叠?



