Hive Date Functions

Date Functions

1.from_unixtime(bigint unixtime[, string format])
select from_unixtime(1237519801, 'yyyy-MM-dd HH:mm:ss');
+----------------------+--+
|         _c0          |
+----------------------+--+
| 2009-03-20 11:30:01  |
+----------------------+--+


2.unix_timestamp()
select unix_timestamp();
+-------------+--+
|     _c0     |
+-------------+--+
| 1653980803  |
+-------------+--+

3.unix_timestamp(string date)
select unix_timestamp('1970-03-20 11:10:10');
+----------+--+
|   _c0    |
+----------+--+
| 6750610  |
+----------+--+

4.unix_timestamp(string date, string pattern)
select unix_timestamp('1970-03-20', 'yyyy-MM-dd');
+----------+--+
|   _c0    |
+----------+--+
| 6710400  |
+----------+--+

5.to_date(string timestamp)
select to_date("1970-01-01 00:00:00");
+-------------+--+
|     _c0     |
+-------------+--+
| 1970-01-01  |
+-------------+--+


6.year(string date)
select year("1970-01-01");
+-------+--+
|  _c0  |
+-------+--+
| 1970  |
+-------+--+


7.quarter(date/timestamp/string)
--1.3.0版本可用

8.month(string date)
select month('2020-01-01')
+------+--+
| _c0  |
+------+--+
| 1    |
+------+--+


9.day(string date) dayofmonth(date)
select day('2015-01-01');
+------+--+
| _c0  |
+------+--+
| 1    |
+------+--+
select dayofmonth('2015-01-01');
+------+--+
| _c0  |
+------+--+
| 1    |
+------+--+


10.hour(string date)
select hour('2022-02-02 11:01:02');
+------+--+
| _c0  |
+------+--+
| 11   |
+------+--+


11.minute(string date)
select minute("2022-01-01 12:09:09");
+------+--+
| _c0  |
+------+--+
| 9    |
+------+--+


12.second(string date)
select second("2022-01-01 12:09:09");
+------+--+
| _c0  |
+------+--+
| 9    |
+------+--+

13.weekofyear(string date)
select weekofyear('2022-05-31');
+------+--+
| _c0  |
+------+--+
| 22   |
+------+--+


14.extract(field FROM source)
select extract(month from '2022-05-31');
--2.2.0版本可用

15.datediff(string enddate, string startdate)
select datediff('2022-05-31','2021-06-25');
+------+--+
| _c0  |
+------+--+
| 340  |
+------+--+

16.date_add(date/timestamp/string startdate, tinyint/smallint/int days)
select date_add("2022-09-09",90);
+-------------+--+
|     _c0     |
+-------------+--+
| 2022-12-08  |
+-------------+--+


17.date_sub(date/timestamp/string startdate, tinyint/smallint/int days)
select date_sub('2022-05-31',1);
+-------------+--+
|     _c0     |
+-------------+--+
| 2022-05-30  |
+-------------+--+


18.from_utc_timestamp({any primitive type} ts, string timezone)
select from_utc_timestamp(2592000000,'UTF');
+------------------------+--+
|          _c0           |
+------------------------+--+
| 1970-01-31 08:00:00.0  |
+------------------------+--+

19.to_utc_timestamp({any primitive type} ts, string timezone)
select to_utc_timestamp(2592000.0,'PST');
+------------------------+--+
|          _c0           |
+------------------------+--+
| 1970-01-31 16:00:00.0  |
+------------------------+--+

20.current_date
--1.2.0版本可用

21.current_timestamp
--1.2.0版本可用

22.add_months(string start_date, int num_months, output_date_format)
select ad_months("2022-05-31",9,"yyyy-MM-dd");
--4.0.0版本可用

23.last_day(string date)
select last_day("2022-05-12");
+-------------+--+
|     _c0     |
+-------------+--+
| 2022-05-31  |
+-------------+--+

24.next_day(string start_date, string day_of_week)
--1.2.0版本可用

25.trunc(string date, string format)
--1.2.0版本可用

26.months_between(date1, date2)
 Example: months_between('1997-02-28 10:30:00', '1996-10-30') = 3.94959677
--1.2.0版本可用

27.date_format(date/timestamp/string ts, string fmt)
Example: date_format('2015-04-08', 'y') = '2015'
--1.2.0版本可用


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值