hive中时间-日期函数的用法

2023-06-15,,

current_date:获取当前日期

用法:select current_date;

输出:2020-12-04

unix_timestamp:获取当前unix时间戳

用法:select unix_timestamp;

输出:1607070544

date_add:返回日期的后n天的日期

例:返回当前时间和当前时间的后10天的时间

用法:select current_date,date_add((select current_date),10);

输出:2020-12-04    2020-12-14

date_sub:返回当前时间的前n天的日期

例:获取当前时间的前10天的日期

用法:select date_sub((select current_date),10);

输出:2020-11-24

weekofyear:返回日期在本年所在的周数

例:获取2021-01-20是2021年第几周

用法:select weekofyear('2020-01-20');

输出:3

datediff(string enddate,string begindate):返回的是begindate和enddate相差的天数

例:2020-10-09和2020-10-29相差几天?

用法:select datediff('2020-10-29','2020-10-09');

输出:20

hive中时间-日期函数的用法的相关教程结束。

《hive中时间-日期函数的用法.doc》

下载本文的Word格式文档,以方便收藏与打印。