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()>>減少時間

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章