hive中時間類date函式

2021-10-22 04:13:52 字數 1081 閱讀 6517

返回值: string 

說明:  對給定的字串日期進行格式化。 

舉例:

hive> select date_format(current_date,'yyyy-mm-dd hh:mm:ss');

返回結果 2021-03-14 00:00:00

hive> select date_format('2019-06-29','yyyy-mm');

返回結果 2019-06

hive> select date_format('2019/06/29','yyyy-mm-dd');

返回結果 null ,說明執行失敗。必須將2019/06/29轉換成2019-06-29格式才能執行。

hive> select date_format(regexp_replace('2019/06/29','/','-'),'yyyy-mm-dd');

返回結果 :2019-06-29

返回值: int 

說明: 返回結束日期減去開始日期的天數。 

舉例:

hive> select datediff('2016-12-30','2016-12-29');

返回結果 1

返回值: string 

說明: 返回開始日期startdate增加days天後的日期。 intdays可以是負數,就程式設計了日期減少函式。

舉例:

hive>select date_add('2016-12-29',10);

返回結果 2017-01-08

返回值: string 

說明: 返回開始日期startdate減少days天後的日期。 

舉例:

hive>select date_sub('2016-12-29',10);

返回結果 2016-12-19

select * from table where datediff(current_timestamp,create_time)<=30;

create_time 為table裡的字段,current_timestamp 返回當前時間 2018-06-01 11:00:00

hive 中時間函式

to date 日期時間轉日期函式 select to date 2015 04 02 13 34 12 輸出 2015 04 02 當前日期和時間 select current timestamp 2018 04 28 11 46 03.136 獲取當前日期,當前是 2018 04 28 sele...

時間date工具類

public class datetool public static date getnow public static string getdate public static string getym public static string getdatetime 獲得當前月的上一 publ...

Date 時間工具類

問題引出 我們每次用到date時間這個類的時候,時間物件轉化為指定的字串,或者把字串轉化為時間物件,等等相對來說會比較麻煩,下面這個時間工具類提供了各種轉化方法,呼叫相應方法就能得到你想要的答案 public class dateutils return parsestring2date dates...