HIVE SQL时间函数

current_timestamp()获取当前时间

select current_timestamp();

输出:2023-11-23 11:31:31.531

unix_timestamp()获取当前时区的UNIX时间戳

select unix_timestamp();

输出:1700710598

from_unixtime()时间戳转日期函数

select from_unixtime(1700710598);

输出:2023-11-23 11:36:38

unix_timestamp(string date)日期转时间戳函数

select unix_timestamp('2023-11-23 11:36:38');

输出:1700710598

提取日期中的年月日时分秒

> select year(current_timestamp());

输出:2023

select month(current_timestamp());

输出:11

select day(current_timestamp());

输出:23

select hour(current_timestamp());

输出:13

select minute(current_timestamp());

输出:39

select second(current_timestamp());

输出:25

weekofyear (string date)日期转周函数

select weekofyear(current_timestamp());

输出:47

日期比较函数datediff(string enddate, string startdate)

select datediff(current_timestamp(),'2023-11-20');

输出:3

日期增加/减少函数

date_add(string startdate, int days)
date_sub (string startdate, int days)

select date_add(current_timestamp(),3);

输出:2023-11-26

select date_sub(current_timestamp(),3);

输出:2023-11-20

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值