码迷,mamicode.com
首页 > 其他好文 > 详细

Hive中yyyymmdd和yyyy-mm-dd日期之间的切换

时间:2017-12-06 00:06:49      阅读:361      评论:0      收藏:0      [点我收藏+]

标签:color   weight   hive   style   amp   substr   time   div   mes   

以2017-12-05和20171205相互转换为例说明

方法1: from_unixtime+ unix_timestamp
--20171205转成2017-12-05 
select from_unixtime(unix_timestamp(20171205,yyyymmdd),yyyy-mm-dd) from dual;

--2017-12-05转成20171205
select from_unixtime(unix_timestamp(2017-12-05,yyyy-mm-dd),yyyymmdd) from dual;

方法2: substr + concat
--20171205转成2017-12-05 
select concat(substr(20171205,1,4),-,substr(20171205,5,2),-,substr(20171205,7,2)) from dual;

--2017-12-05转成20171205
select concat(substr(2017-12-05,1,4),substr(2017-12-05,6,2),substr(2017-12-05,9,2)) from dual;

 

Hive中yyyymmdd和yyyy-mm-dd日期之间的切换

标签:color   weight   hive   style   amp   substr   time   div   mes   

原文地址:http://www.cnblogs.com/huangbiquan/p/7989974.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!