Hive時間處理

2022-07-15 12:27:13 字數 1351 閱讀 1992

時間戳:unix_timestamp

時間戳轉日期:from_unixtime

時間hive語句

上月1號

trunc(add_months(current_date(),-1),'mm')

本月1號

trunc(current_date(),'mm')

下月1號

trunc(add_months(current_date(),1),'mm')

本月時間範圍

substr(date,0,10)>=trunc(current_date(),'mm') and substr(date,0,10)

時間偏移乙個月

add_months(current_date,-1)

上月時間範圍

substr(date,0,10)>=trunc(add_months(current_date(),-1),'mm') and substr(date,0,10)

近一周資料

substr(date,0,10)>=date_sub(current_date(),7) and substr(date,0,10)

近一月資料

substr(date,0,10)>=date_sub(current_date(),30) and substr(date,0,10)

本週周一日期

date_sub(current_date(),cast(date_format(current_date(),'u') as int)-1)

上週周一日期

date_sub(current_date(),cast(date_format(current_date(),'u') as int)-1+7)

上週時間

substr(date,0,10)>=date_sub(current_date(),cast(date_format(current_date(),'u') as int)-1+7) and substr(date,0,10)

本週時間

substr(date,0,10)>=date_sub(current_date(),cast(date_format(current_date(),'u') as int)-1) and substr(date,0,10)

今年年初日期

trunc(current_date(),'yyyy')

今年(到昨日)

substr(date,0,10)>=trunc(current_date(),'yyyy') and substr(date,0,10)

今年(到上月)

substr(date,0,10)>=trunc(current_date(),'yyyy') and substr(date,0,10)

Hive時間處理函式

from unixtime bigint unixtime string format 返回值 string 說明 轉化unix時間戳 從1970 01 01 00 00 00 utc到指定時間的秒數 到當前時區的時間格式 舉例 hive select from unixtime 150181993...

HIVE 各種時間格式處理

方法一 date format 只支援yyyy mm dd yyyymmdd000000 select date format 2019 10 07 yyyymmdd000000 20191007000000 方法二 from unixtime unix timestamp select from ...

hive中的時間處理函式

返回值 string 說明 轉化unix時間戳 從1970 01 01 00 00 00 utc到指定時間的秒數 到當前時區的時間格式 舉例 hive select from unixtime 1323308943,yyyymmdd from dual 20111208 獲取當前unix時間戳函式 ...