Hive date/timestamp/date_sub/date_add/date_format/日期时间格式转换
Posted 二十六画生的博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Hive date/timestamp/date_sub/date_add/date_format/日期时间格式转换相关的知识,希望对你有一定的参考价值。
-- Hive 只有date('2022-06-09')、TIMESTAMP('2022-07-15 02:21:32.000000') 2个日期类型,没有datetime类型。
select
now(),
current_timestamp(),
current_date(),
date_sub(current_date(), 2),
date_add(current_date(), 2),
date_add('2022-06-09', 2) as c2,
date_sub('2022-06-09 12:13:14', 2) as c3,
date_format('2022-06-09 12:13:14', 'dd-MM-yyyy') as c4,
date_format('2022-06-09 12:13:14', 'yyyy-MM-dd') as c5,
date_format('2022-06-09 12:13:14', 'yyyy-MM') as c6,
date_format('2022-06-09 12:13:14', 'MM') as c7,
date_format(current_date(), 'MM') as c8,
from_unixtime(1657851692, 'yyyy-MM-dd HH:mm:ss') as c9,
date_sub(
from_unixtime(1657851692, 'yyyy-MM-dd HH:mm:ss'),
2
) as c10,
to_date('2018-12-08 10:03:01'),
date_sub(to_date('2018-12-08 10:03:01'), 2),
cast('2022-05-10' as date) c11,
date_sub(cast('2022-05-10' as date), 2) as c12,
date_format(cast('2022-05-10' as date), 'MM') as c13,
--cast('2018-12-08 10:03:01' as datetime) as c14, --UnsupportedOperationException: Sql 1 class org.apache.calcite.sql.SqlIdentifier: datetime
weekofyear('2022-07-15') as c15,
cast(1657851692 as timestamp) as c16, --2022-07-15 02:21:32.000000
date_format(cast(1657851692 as timestamp), 'yyyy-MM-dd') as c17, --2022-07-15
date_format(now(), 'yyyy-MM-dd') as c18, --2022-07-15
quarter('2022-11-10') as c19,
add_months('2022-07-15', 2) as c20,
add_months('2022-07-15', -2) as c21,
date_sub(cast(1657851692 as timestamp), 2) as c22
--add_years('2022-07-15', 2) as c22, --No match found for function signature add_years(<CHARACTER>, <NUMERIC>)
--add_days('2022-07-15', 2) as c23 --No match found for function signature add_days(<CHARACTER>, <NUMERIC>)
Hive版本:
select version();
3.0.1 b426c.... |
务必注意输入类型和返回类型!
LanguageManual UDF - Apache Hive - Apache Software Foundation Hive函数-官方文档
以上是关于Hive date/timestamp/date_sub/date_add/date_format/日期时间格式转换的主要内容,如果未能解决你的问题,请参考以下文章
Hive date/timestamp/date_sub/date_add/date_format/日期时间格式转换
Hive date/timestamp/date_sub/date_add/date_format/日期时间格式转换