with t as ( select unix_timestamp('10-01-2019' , 'dd-MM-yyyy') as dt )
select from_unixtime(dt,'dd') as Date,
from_unixtime(dt,'MMMM') as Month,
from_unixtime(dt,'YYYY') as Year
from t;
结果
Total MapReduce CPU Time Spent: 2 seconds 720 msec
OK
10 January 2019
Time taken: 23.206 seconds, Fetched: 1 row(s)
with your_data as(
select stack(3,'10-01-2019',
'20-02-2019',
'22-03-2019'
) as dt
) --use your table instead of this
select dt[0] as day,
dt[1] as month,
dt[2] as year
from ( select split(dt,'-') as dt from your_data )s;
结果:
OK
day month year
10 01 2019
20 02 2019
22 03 2019
Time taken: 0.081 seconds, Fetched: 3 row(s)
我们需要使用 from_unixtime and unix_timestamp 函数来解析日期。 那么 split the field 在 subquery 提取日期,月份,年份。。 Example:hive> select dt[0] day,dt[1] month,dt[2] year from( select split(from_unixtime(unix_timestamp("10-01-2019",'dd-MM-yyyy'),'dd-MMMM-yyyy'),'-')dt )e;Result: ``` day month year 10 January 2019
3条答案
按热度按时间nwlls2ji1#
试试这个
结果
ee7vknir2#
使用split():
结果:
c86crjj03#
我们需要使用
from_unixtime and unix_timestamp
函数来解析日期。那么
split the field
在subquery
提取日期,月份,年份。。Example:
hive> select dt[0] day,dt[1] month,dt[2] year from( select split(from_unixtime(unix_timestamp("10-01-2019",'dd-MM-yyyy'),'dd-MMMM-yyyy'),'-')dt )e;
Result:
```day month year
10 January 2019