我正在寻找帮助转换下面的sql查询到hive支持的日期格式。请协助。GP:SQL
select to_date('19800302000000','yyyymmddhh24miss') date_of_birth
GP输出:1980年3月2日GP查询:
extract(year from age(current_date-1, to_date(b.birthday,'yyyymmddhh24miss'))) age
我们在Hive里也有类似的情况,请帮帮我们。
dw1jzc5e1#
对于select to_date('19800302000000','yyyymmddhh24miss'),请使用此select from_unixtime(unix_timestamp('19800302000000','yyyyMMddhhmmSS')) .如果你不想要时间部分,使用这个select to_date(from_unixtime(unix_timestamp('19800302000000','yyyyMMddhhmmSS')))。对于extract(year from age(current_date-1, to_date(b.birthday,'yyyymmddhh24miss'))) age使用下面代码。2它应该给予昨天和出生日期之间的年份差。
select to_date('19800302000000','yyyymmddhh24miss')
select from_unixtime(unix_timestamp('19800302000000','yyyyMMddhhmmSS'))
select to_date(from_unixtime(unix_timestamp('19800302000000','yyyyMMddhhmmSS')))
select year(current_date() - interval 1 day ) - year(from_unixtime(unix_timestamp('19800302000000','yyyyMMddhhmmSS'))) age
1条答案
按热度按时间dw1jzc5e1#
对于
select to_date('19800302000000','yyyymmddhh24miss')
,请使用此select from_unixtime(unix_timestamp('19800302000000','yyyyMMddhhmmSS'))
.如果你不想要时间部分,使用这个
select to_date(from_unixtime(unix_timestamp('19800302000000','yyyyMMddhhmmSS')))
。对于
extract(year from age(current_date-1, to_date(b.birthday,'yyyymmddhh24miss'))) age
使用下面代码。2它应该给予昨天和出生日期之间的年份差。