Hive日期函式

2021-08-13 19:14:30 字數 1906 閱讀 8464

hive日期函式

函式用法

含參方式

用法備註

hive日期函式

函式用法

含參方式

用法備註

date2datekey

date格式轉換成datekey

date2datekey(string date/time)

date2datekey('2017-09-01')

返回:'20170901'

date_add

往後加上days

date_add(string startdate, int days)

date_add('2017-12-08',10)

返回: '2017-12-18'

date_sub

往前減少days

date_sub (string startdate, int days)

date_add('2012-12-18',10)

返回:'2012-12-08'

datediff

日期差函式

datediff(string enddate, string begindate)

datediff('2017-09-03','2017-09-01')

返回:2

datekey2date

date key格式轉換成date

datekey2date(string datekey)

datekey2date('20170901')

返回:'2017-09-01'

day獲取日期函式

day(string date)

('2011-12-08 10:03:01')

返回:'08'

from_unixtime

日期函式unix時間戳轉日期函式

from_unixtime(bigint unixtime,[ string format])

from_unixtime(1323308943,'yyyymmdd')

返回:'20111208'

hour

獲取小時函式

hour(string date)

('2011-12-08 10:03:01')

返回:'10'

minute

獲取分鐘函式

minute(string date)

('2011-12-08 10:03:01')

返回:'03'

month

獲取月函式

month(string date)

('2011-12-08 10:03:01')

返回:'12'

second

獲取秒函式

second(string date)

('2011-12-08 10:03:01')

返回:'01'

to_date

轉換成日期

to_date('string time')

to_date(』2011-12-08 10:03:01′) 

返回:'2011-12-08'

unix_timestamp

日期轉unix時間戳函式

unix_timestamp(string format)

unix_timestamp(』2011-12-07 13:01:03′)

返回:1323309615

weekofyear

當前週數

weekofyear(string date)

weekofyear('2011-12-08 10:03:01')

返回:49

year

獲取年函式

year(string date)

year('2011-12-08 10:03:01')

返回:'2011'

Hive日期函式

1 unix timestamp 2018 12 05 08 45 17 作用 統計從1970年開始到現在的秒數 2 from unixtime 1525509615,yyyymmdd 作用 日期函式unix時間戳轉日期函式 3 to date 2018 12 08 10 08 01 作用 返回日期...

Hive日期函式

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

hive日期函式

1.獲取到當前日期 hive select current date ok2020 11 14time taken 0.036 seconds,fetched 1 row s 2.獲取到當前日期和時間 hive select current timestamp ok2020 11 1409 38 2...