本文主要是介绍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()>>减少时间
这篇关于Postgresql、HiveQL时间日期比较及加减写法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!