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()>>减少时间

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