1. 程式人生 > >Postgresql、HiveQL時間日期比較及加減寫法

Postgresql、HiveQL時間日期比較及加減寫法

一、postgreSQL

----當前時間 now()   >>2018-09-14 16:46:51.103709+08 current_timestamp   >>2018-09-14 16:47:58.547305+08----當前日期 current_date     >>2018-09-14

----小於某個固定時間 create_time < to_date('2018-09-04 00:00:00', 'yyyy-MM-dd hh24:mi:ss')

----小於某個日期 to_date(to_char(create_time, 'yyyy-MM-dd'),'yyyy-MM-dd') < to_date(to_char(update_time, 'yyyy-MM-dd'),'yyyy-MM-dd')

----時間擷取後分組 group by to_char(create_time, 'yyyyMMdd')

----轉換為數值型別 to_number(to_char(create_time, 'yyyyMMdd'),'99999999')

----時間擷取date_trunc('day', create_time)  >>2018-09-14 00:00:00

----時間加減 增加兩天:timejoin + interval '2 day' 退後某幾天:timejoin - (matchperiod || 'day'):: interval

二、HiveQL

----當前時間

CURRENT_TIMESTAMP   >>2018-09-14 16:11:16.279 from_unixtime(unix_timestamp())   >>2018-09-14 16:13:44----當前日期 current_date    >>2018-09-14

----小於當前時間 should_time < CURRENT_TIMESTAMP should_time < from_unixtime(unix_timestamp())

----小於某個固定時間 should_time < from_unixtime(unix_timestamp('2018-09-14 03:10:00'))

----小於某個時間 should_time < from_unixtime(unix_timestamp(create_time)) should_time < from_unixtime(unix_timestamp(create_time), 'yyyy-MM-dd HH:mm:ss')

----小於某個日期 from_unixtime(unix_timestamp(should_time), 'yyyy-MM-dd') < from_unixtime(unix_timestamp(create_time), 'yyyy-MM-dd')

----時間擷取後分組 group by from_unixtime(unix_timestamp(create_time), 'yyyyMMdd')

----時間擷取 to_date()>>擷取日期2018-09-14 year()>>擷取年2018 day()>>擷取天14

----時間加減 date_add()>>增加時間 date_sub()>>減少時間