Hive常用系统函数-时间函数

关于Hive常用的时间处理函数

函数参数格式解释
from_unixtimefrom_unixtime(bigint unixtime[, string format])将unix时间戳转换为当前所在时区的字符串时间,格式为"yyyy-MM-dd HH:mm:ss"
unix_timestampunix_timestamp()以秒为单位获取当前的Unix时间戳。
unix_timestampunix_timestamp(string date)将格式为"yyyy-MM-dd HH:mm:ss"的字符串时间转换为Unix时间戳
unix_timestampunix_timestamp(string date, string pattern)将格式为pattern的字符串时间转换为Unix时间戳,若转换失败则返回0
to_dateto_date(string timestamp)传入字符串时间,返回"yyyy-MM-dd"日期
yearyear(string date)返回给定字符串时间所在的年,例如:year(“1970-01-01 00:00:00”) = 1970; year(“1970-01-01”) = 1970
quarterquarter(date/timestamp/string)返回给时间所在的季度,例如: year(“1970-04-01”) =2
monthmonth(string date)返回给定时间所在的月,例如: month(“1970-05-01”) = 5
dayday(string date) dayofmonth(date)返回给定时间在当月的第几天,例如: day(“1970-05-01”) = 1
minuteminute(string date)返回给定时间所在分钟,例如: minute(“2009-07-30 12:58:59”) = 58
secondsecond(string date)返回给定时间所在秒数,例如: second(“2009-07-30 12:58:59”) = 59
weekofyearweekofyear(string date)返回给定时间在该年的第几周,例如: weekofyear(“1970-11-01”) = 44
extractextract(field FROM source)将给定的field函数应用在时间source。例如:select extract(month from “2016-10-20”)=10;extract(dayofweek from “1970-11-01”)=44
datediffdatediff(string enddate, string startdate)计算enddate与startdate相差的天数
date_adddate_add(date/timestamp/string startdate, tinyint/smallint/int days)将startdate加上给定的天数并返回新的日期
from_utc_timestampfrom_utc_timestamp({any primitive type} ts, string timezone)将UTC时间戳转换为给定时区的时间,例如from_utc_timestamp(timestamp ‘1970-01-30 16:00:00’,‘PST’)的返回值为"1970-01-30 08:00:00"
to_utc_timestampto_utc_timestamp({any primitive type} ts, string timezone)将给定时区的时间转换为UTC时间戳,例如to_utc_timestamp(timestamp ‘1970-01-30 16:00:00’,‘PST’)的返回值为"1970-01-31 00:00:00"
current_datecurrent_date查询当前日期,同一查询中current_date都一样
current_timestampcurrent_timestamp查询当前时间,同一查询中current_timestamp都一样
add_monthsadd_months(string start_date, int num_months, output_date_format)返回start_date加上num_months个月后的时间,并指定格式为output_date_format
last_daylast_day(string date)返回date所在月的最后一天的日期
next_daynext_day(string start_date, string day_of_week)返回位于start_date后,且所在星期天数为day_of_week的日期。例如:next_day(‘2015-01-14’,‘TU’)= “2015-01-20”(day_of_week可以为 Mo, tue, FRIDAY等形式)
trunctrunc(string date, string format)将日期date截断到format格式,例如trunc(‘2015-03-17’,‘MM’)= “2015-03-01”。(支持的格式有:MONTH / MON / MM,YEAR / YYYY / YY)
months_betweenmonths_between(date1, date2)计算date1与date2相差的月数,精确到小数。例如months_between(‘1997-02-28 10:30:00’, ‘1996-10-30’) = 3.94959677
date_formatdate_format(date/timestamp/string ts, string fmt)将时间戳转换为指定格式,例如:date_format(‘2015-04-08’, ‘y’) = ‘2015’
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值