以yyyymmdd格式显示今天在hive中的日期格式

时间:2015-07-23 15:35:30

标签: hive

我正在尝试编写一个hive查询来从今天的分区中获取数据。这是我的疑问:

select * from testtable
where data_dt ='date +%Y%m%d';

我需要帮助将日期转换为yyyyMMdd格式。

非常感谢。

2 个答案:

答案 0 :(得分:1)

配置单元中有几个功能可用于以所需格式检索今天的日期。

试试这个:

从table_name中选择from_unixtime(unix_timestamp(),'yyyyMMdd');

unix_timestamp():此函数返回一个unix时间戳。

from_unixtime():此函数用于以所需格式返回日期。

有关hive中内置函数的更多信息,请尝试

显示功能;

描述函数function_name;

描述函数扩展function_name;

答案 1 :(得分:0)

试试这个:

select * 
from mytable 
where mydate=regexp_replace(to_date(from_unixtimestamp())),'-','')
;

当我测试使用时:

select regexp_replace(to_date(from_unixtimestamp())),'-','') as yyyyMMdd from dual;

我得到了输出:20150723

相关问题