hive教程:获取当前日期时间

current_timestamp()

返回当前时间戳,返回格式:yyyy-MM-dd HH-mm-ss.毫秒,精确到毫秒

select current_timestamp()

注意

执行查询时,没有毫秒,但 substr() 截取时,如果是负数(从后往前截取),会有毫秒,所以截取时,不要负数(从后往前截取)

如下,用负数截取时间:

select substr(current_timestamp(),-12)

执行结果:07:49:04.071,有毫秒

日期时间

防止出现毫秒,所以用截取

select substr(current_timestamp(),1,19)

执行结果:2022-05-07 23:03:24

日期

SELECT current_date()
SELECT current_date

执行结果:2022-05-07

时间

select substr(current_timestamp(),12,8)

执行结果:23:03:46

根据时间戳格式化

详见:https://www.malaoshi.top/show_1IX3GZEIvQcj.html


原文出处:/show_1IX3GZ136RMD.html