2018 04 28 hive 常用的日期函式

2021-08-19 13:14:13 字數 1456 閱讀 1952

## 當前日期和時間

select current_timestamp();

-- 2018-04-28 11:46:03.136

## 獲取當前日期,當前是 2018-04-28

select current_date;

orselect current_date();

-- 2018-04-28

## 獲取unix系統下的時間戳

select unix_timestamp();

-- 1524884881

## 當前是 2018-04-28

select substr(current_timestamp, 0, 10);

-- 2018-04-28

## 當前是 2018-04-28

select date_sub(current_date, 1);

-- 2018-04-27

## yyyy-mm-dd hh:mm:ss 擷取日期

select to_date("2017-10-22 10:10:10");

-- 2017-10-22

## 兩個日期之間的天數差

select datediff("2017-10-22", "2017-10-12");

-- 10

select datediff("2017-10-22 10:10:10", "2017-10-12 23:10:10");

-- 10

select datediff("2017-10-22 01:10:10", "2017-10-12 23:10:10");

-- 10

## 時間擷取

select from_unixtime(cast(substr("1504684212155", 0,10) as int)) dt;

-- 2017-09-06 15:50:12

## 時間戳轉日期

## 語法: to_date(string timestamp)

hive的常用函式

型別轉換函式 cast 1 as bigint 日期函式 返回值型別 string from unixtime bigint unixtime string format 例 from unixtime 0 1970 01 01 00 00 00 bigint unix timestamp 獲取當前...

hive 解密 Hive 常用函式

2.concat str1,sep,str2,sep,str3,和 concat ws sep,str1,str2,str3,字串連線函式,需要是 string型字段。如果4個字段,想得到如下結果,看下兩個函式的區別 eg 1 select concat 江蘇省 南京市 玄武區 徐莊軟體園 2 se...

Hive 常用操作

hive f script.q 可以直接執行在指令碼中的命令 hive e select from users 直接執行sql語句 hive s e select from users 靜默的方式執行,不顯示輸入資訊只顯示輸出結果 hive v 將會列印所執行的sql語句 hive h 192.16...