Hive 日期函数

Hive date函数
hive没有专门的日期类型,使用字符串(string)来存储日期类型,比如 '2012-12-29', '2012-12-29 10:00:00'。
形如 'yyyy-mm-dd' 的数据为 date类型数据,形如 'yyyy-mm-dd HH:MM:SS'的数据为time类型数据。
用一个整数(int) 来表示日期,比如 20121229 表示 '2012-12-29', 形如 'yyyymmdd' 的数据我们一般称为 datekey类型。
0: jdbc:hive2://localhost:10000> select to_date('2019-12-29 16:11:00');
+-------------+--+
| _c0 |
+-------------+--+
| 2019-12-29 |
+-------------+--+

0: jdbc:hive2://localhost:10000> select datediff('2012-12-29 10:00:00', '2012-12-28 23:00:00');
+------+--+
| _c0 |
+------+--+
| 1 |
+------+--+


0: jdbc:hive2://localhost:10000> select date_add('2012-12-29 10:00:00', 1);
+-------------+--+
| _c0 |
+-------------+--+
| 2012-12-30 |
+-------------+--+

0: jdbc:hive2://localhost:10000> select date_sub('2012-12-29', 1);
+-------------+--+
| _c0 |
+-------------+--+
| 2012-12-28 |
+-------------+--+
0: jdbc:hive2://localhost:10000> select year('2012-12-29');
+-------+--+
| _c0 |
+-------+--+
| 2012 |
+-------+--+
1 row selected (0.577 seconds)
0: jdbc:hive2://localhost:10000> select month('2012-12-29');
+------+--+
| _c0 |
+------+--+
| 12 |
+------+--+
1 row selected (0.553 seconds)
0: jdbc:hive2://localhost:10000> select day('2012-12-29');
+------+--+
| _c0 |
+------+--+
| 29 |
+------+--+

原文地址:https://www.cnblogs.com/songyuejie/p/13025822.html