Hive中时间函数汇总

来源:互联网 发布:手机订火车票软件 编辑:程序博客网 时间:2024/06/14 01:16

Hive中时间函数汇总

编号 函数 功能 语法 返回值类型 举例 备注 1 from_unixtime 将时间戳转换为时间格式 from_unixtime(bigint unixtime[, string format]) string select from_unixtime(1462361193,’yyyy-MM-dd HH:mm:ss’) from test 当字段time为string类型时,应该将其转换为int类型, select from_unixtime(cast(time as int),’yyyyMMddHH’) from test 2 unix_timestamp 日期转UNIX时间戳 unix_timestamp(string date) bigint select unix_timestamp(’2016-05-04 19:00:00′) from test 转换格式为“yyyy-MM-dd HH:mm:ss“的日期 3 unix_timestamp 指定格式日期转UNIX时间戳 unix_timestamp(string date, string pattern) bigint select unix_timestamp(’20160504 19:00:00′,’yyyyMMdd HH:mm:ss’) from test 如果转化失败,则返回0 4 unix_timestamp 获取当前UNIX时间戳 unix_timestamp() bigint select unix_timestamp() from test 5 to_date 日期时间转日期 to_date(string timestamp) string select to_date(’2016-05-04 19:00:00′) from test 返回日期时间字段中的日期部分 6 year 日期转年 year(string date) int select year(‘2016-05-04 19:00:00’) from test 返回日期中的年, 相应地,month、day、hour、minute、second返回月、日、时、分、秒 7 datadiff 日期比较求差 datediff(string enddate, string startdate) int select datediff(’2015-11-02′,’2016-05-04′) from test 返回结束日期减去开始日期的天数 8 date_add 日期增加 date_add(string startdate, int days) string select date_add(‘2016-05-04’, 520) from test 返回开始日期startdate增加days天后的日期, data_sub类似,返回开始日期startdate减去days天后的日期
0 0
原创粉丝点击