select from_unixtime(unix_timestamp('20190901','yyyymmdd'));;好+ ---------------------- +| _c0 |+ ---------------------- +| 2019-01-01 00:09:00 |+ ---------------------- +
所需的输出是2019-09-01 00:00:00。我在做什么错?
想通了。毫米是分钟,毫米是月。
应该是yyyyMMdd而不是yyyymmdd
有效的方法是使用substr和concat_ws:
with your_table as (select 20190901 as initial_date)
select concat_ws('-',substr(initial_date, 1, 4), substr(initial_date, 5, 2), substr(initial_date, 7, 2)) as dt from your_table;
结果
2019-09-01
如果您更喜欢使用unix_timestamp,则使用正确的格式'yyyyMMdd'
:
select from_unixtime(unix_timestamp('20190901','yyyyMMdd'));
在此处查看数据格式:SimpleDateFormat