十三 Hive中日期操作總結

2021-10-06 12:30:02 字數 2095 閱讀 7834

1、獲取當前時間

hive (

default

)>

select

current_date

;2020-05

-26hive (

default

)>

select

current_timestamp

;2020-05

-2616:03:09.012

2、date_format函式-日期格式化
hive (

default

)>

select

current_date

,date_format(

current_date

,'yyyy/mm');

2020-05

-262020

/05

3、date_add函式(加減日期)
hive (

default

)>

select date_add(

'2019-02-10',-

1);2019-02

-09hive (

default

)>

select date_add(

'2019-02-10',1

);2019-02

-11

4、date_sub函式(加減日期)與add相反
hive (

default

)>

select date_sub(

'2019-02-10',1

),date_sub(

'2019-02-10',-

1);ok

_c0 _c1

2019-02

-092019-02

-11

5、next_day函式-取指定日期的下乙個週幾
(1)取當前天的下乙個周一

hive (gmall)

>

select next_day(

'2019-02-12'

,'mo'

)2019-02

-18說明:星期一到星期日的英文(monday,tuesday、wednesday、thursday、friday、saturday、sunday)

(2)取當前周的周一

hive (gmall)

>

select date_add(next_day(

'2019-02-12'

,'mo'),

-7);

2019-02

-11

6、last_day函式(求當月最後一天日期)
hive (gmall)

>

select last_day(

'2019-02-10');

2019-02

-28

7、取指定日期的年、月、日
hive (

default

)>

select

current_date

,year

(current_date),

month

(current_date),

day(

current_date);

ok_c0 _c1 _c2 _c3

2020-05

-262020

526

8、指定日期所在年份的第多少周
hive (

default

)>

select weekofyear(

'2020-05-26');

_c022

9、日期比較函式datediff(string enddate,string startdate)
hive (

default

)>

select datediff(

'2018-02-08'

,'2018-02-01');

ok_c0

7

Hive中日期函式總結

hive中日期函式總結 1.時間戳函式 日期轉時間戳 從1970 01 01 00 00 00 utc到指定時間的秒數 select unix timestamp 獲得當前時區的unix時間戳 select unix timestamp 2017 09 15 14 23 00 select unix...

Hive中日期函式總結

hive中日期函式總結 1.時間戳函式 日期轉時間戳 從1970 01 01 00 00 00 utc到指定時間的秒數 select unix timestamp 獲得當前時區的unix時間戳 select unix timestamp 2017 09 15 14 23 00 select unix...

HIVE中日期轉換

本來是sql查出來是兩條資料 select groupid,shopid,shopname,deliverytime,sku,transport type from ods amz group fee where dt 2020 12 11 and sku fba syhg372 30cm mm表示...