hive中 日期格式转化办法:
2014-11-10 和 20141110相互转化的办法:
1.from_unixtime && unix_timestamp
-- 20141110
select from_unixtime(unix_timestamp('2014-11-10','yyyy-mm-dd'),'yyyymmdd') from default.dual;
-- 2014-11-10
select from_unixtime(unix_timestamp('20141110','yyyymmdd'),'yyyy-mm-dd') from default.dual;
2.substr + concat
-- 20141110
select concat(substr('2014-11-10',1,4),substr('2014-11-10',6,2),substr('2014-11-10',9,2)) from default.dual;
-- 2014-11-10
select concat(substr('20141110',1,4),'-',substr('20141110',5,2),'-',substr('20141110',7,2)) from default.dual;
附加:hive 获取当前时间
select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss') from default.dual;
网友评论