hive 时间函数
1.datediff可以传入timestamp类型参数
|
Return Type
|
Name(Signature)
|
Description
|
|
string
|
from_unixtime(bigint unixtime[, string format])
|
Converts the number of seconds from unix epoch (1970-01-01 00:00:00 UTC) to a string representing the timestamp of that moment in the current system time zone in the format of "1970-01-01 00:00:00".
|
|
bigint
|
unix_timestamp()
|
Gets current Unix timestamp in seconds. This function is not deterministic and its value is not fixed for the scope of a query execution, therefore prevents proper optimization of queries - this has been deprecated since 2.0 in favour of CURRENT_TIMESTAMP constant.
|
|
bigint
|
unix_timestamp(string date)
|
Converts time string in format yyyy-MM-dd HH:mm:ss to Unix timestamp (in seconds), using the default timezone and the default locale, return 0 if fail: unix_timestamp('2009-03-20 11:30:01') = 1237573801
|
|
bigint
|
unix_timestamp(string date, string pattern)
|
Convert time string with given pattern (see [http://docs.oracle.com/javase/tutorial/i18n/format/simpleDateFormat.html]) to Unix time stamp (in seconds), return 0 if fail: unix_timestamp('2009-03-20', 'yyyy-MM-dd') = 1237532400.
|
|
pre 2.1.0: string
2.1.0 on: date
|
to_date(string timestamp)
|
Returns the date part of a timestamp string (pre-Hive 2.1.0): to_date("1970-01-01 00:00:00") = "1970-01-01". As of Hive 2.1.0, returns a date object.
Prior to Hive 2.1.0 (HIVE-13248) the return type was a String because no Date type existed when the method was created.
|
|
int
|
year(string date)
|
Returns the year part of a date or a timestamp string: year("1970-01-01 00:00:00") = 1970, year("1970-01-01") = 1970.
|
|
int
|
quarter(date/timestamp/string)
|
Returns the quarter of the year for a date, timestamp, or string in the range 1 to 4 (as of Hive 1.3.0). Example: quarter('2015-04-08') = 2.
|
|
int
|
month(string date)
|
Returns the month part of a date or a timestamp string: month("1970-11-01 00:00:00") = 11, month("1970-11-01") = 11.
|
|
int
|
day(string date) dayofmonth(date)
|
Returns the day part of a date or a timestamp string: day("1970-11-01 00:00:00") = 1, day("1970-11-01") = 1.
|
|
int
|
hour(string date)
|
Returns the hour of the timestamp: hour('2009-07-30 12:58:59') = 12, hour('12:58:59') = 12.
|
|
int
|
minute(string date)
|
Returns the minute of the timestamp.
|
|
int
|
second(string date)
|
Returns the second of the timestamp.
|
|
int
|
weekofyear(string date)
|
Returns the week number of a timestamp string: weekofyear("1970-11-01 00:00:00") = 44, weekofyear("1970-11-01") = 44.
|
|
int
|
extract(field FROM source)
|
Retrieve fields such as days or hours from source (as of Hive 2.2.0). Source must be a date, timestamp, interval or a string that can be converted into either a date or timestamp. Supported fields include: day, dayofweek, hour, minute, month, quarter, second, week and year.
Examples:
select extract(month from "2016-10-20") results in 10.
select extract(hour from "2016-10-20 05:06:07") results in 5.
select extract(dayofweek from "2016-10-20 05:06:07") results in 5.
select extract(month from interval '1-3' year to month) results in 3.
select extract(minute from interval '3 12:20:30' day to second) results in 20.
|
|
int
|
datediff(string enddate, string startdate)
|
Returns the number of days from startdate to enddate: datediff('2009-03-01', '2009-02-27') = 2.
|
|
pre 2.1.0: string
2.1.0 on: date
|
date_add(date/timestamp/string startdate, tinyint/smallint/int days)
|
Adds a number of days to startdate: date_add('2008-12-31', 1) = '2009-01-01'.
Prior to Hive 2.1.0 (HIVE-13248) the return type was a String because no Date type existed when the method was created.
|
|
pre 2.1.0: string
2.1.0 on: date
|
date_sub(date/timestamp/string startdate, tinyint/smallint/int days)
|
Subtracts a number of days to startdate: date_sub('2008-12-31', 1) = '2008-12-30'.
Prior to Hive 2.1.0 (HIVE-13248) the return type was a String because no Date type existed when the method was created.
|
|
timestamp
|
from_utc_timestamp({any primitive type} ts, string timezone)
|
Converts a timestamp* in UTC to a given timezone (as of Hive 0.8.0).
* timestamp is a primitive type, including timestamp/date, tinyint/smallint/int/bigint, float/double and decimal.
Fractional values are considered as seconds. Integer values are considered as milliseconds. For example, from_utc_timestamp(2592000.0,'PST'), from_utc_timestamp(2592000000,'PST') and from_utc_timestamp(timestamp '1970-01-30 16:00:00','PST') all return the timestamp 1970-01-30 08:00:00.
|
|
timestamp
|
to_utc_timestamp({any primitive type} ts, string timezone)
|
Converts a timestamp* in a given timezone to UTC (as of Hive 0.8.0).
* timestamp is a primitive type, including timestamp/date, tinyint/smallint/int/bigint, float/double and decimal.
Fractional values are considered as seconds. Integer values are considered as milliseconds. For example, to_utc_timestamp(2592000.0,'PST'), to_utc_timestamp(2592000000,'PST') and to_utc_timestamp(timestamp '1970-01-30 16:00:00','PST') all return the timestamp 1970-01-31 00:00:00.
|
|
date
|
current_date
|
Returns the current date at the start of query evaluation (as of Hive 1.2.0). All calls of current_date within the same query return the same value.
|
|
timestamp
|
current_timestamp
|
Returns the current timestamp at the start of query evaluation (as of Hive 1.2.0). All calls of current_timestamp within the same query return the same value.
|
|
string
|
add_months(string start_date, int num_months, output_date_format)
|
Returns the date that is num_months after start_date (as of Hive 1.1.0). start_date is a string, date or timestamp. num_months is an integer. If start_date is the last day of the month or if the resulting month has fewer days than the day component of start_date, then the result is the last day of the resulting month. Otherwise, the result has the same day component as start_date. The default output format is 'yyyy-MM-dd'.
Before Hive 4.0.0, the time part of the date is ignored.
As of Hive 4.0.0, add_months supports an optional argument output_date_format, which accepts a String that represents a valid date format for the output. This allows to retain the time format in the output.
For example :
add_months('2009-08-31', 1) returns '2009-09-30'.
add_months('2017-12-31 14:15:16', 2, 'YYYY-MM-dd HH:mm:ss') returns '2018-02-28 14:15:16'.
|
|
string
|
last_day(string date)
|
Returns the last day of the month which the date belongs to (as of Hive 1.1.0). date is a string in the format 'yyyy-MM-dd HH:mm:ss' or 'yyyy-MM-dd'. The time part of date is ignored.
|
|
string
|
next_day(string start_date, string day_of_week)
|
Returns the first date which is later than start_date and named as day_of_week (as of Hive 1.2.0). start_date is a string/date/timestamp. day_of_week is 2 letters, 3 letters or full name of the day of the week (e.g. Mo, tue, FRIDAY). The time part of start_date is ignored. Example: next_day('2015-01-14', 'TU') = 2015-01-20.
|
|
string
|
trunc(string date, string format)
|
Returns date truncated to the unit specified by the format (as of Hive 1.2.0). Supported formats: MONTH/MON/MM, YEAR/YYYY/YY. Example: trunc('2015-03-17', 'MM') = 2015-03-01.
|
|
double
|
months_between(date1, date2)
|
Returns number of months between dates date1 and date2 (as of Hive 1.2.0). If date1 is later than date2, then the result is positive. If date1 is earlier than date2, then the result is negative. If date1 and date2 are either the same days of the month or both last days of months, then the result is always an integer. Otherwise the UDF calculates the fractional portion of the result based on a 31-day month and considers the difference in time components date1 and date2. date1 and date2 type can be date, timestamp or string in the format 'yyyy-MM-dd' or 'yyyy-MM-dd HH:mm:ss'. The result is rounded to 8 decimal places. Example: months_between('1997-02-28 10:30:00', '1996-10-30') = 3.94959677
|
|
string
|
date_format(date/timestamp/string ts, string fmt)
|
Converts a date/timestamp/string to a value of string in the format specified by the date format fmt (as of Hive 1.2.0). Supported formats are Java SimpleDateFormat formats – https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html. The second argument fmt should be constant. Example: date_format('2015-04-08', 'y') = '2015'.
date_format can be used to implement other UDFs, e.g.:
dayname(date) is date_format(date, 'EEEE')
dayofyear(date) is date_format(date, 'D')
|
hive 时间函数的更多相关文章
- Hive 时间函数总结【转】
1.日期函数UNIX时间戳转日期函数: from_unixtime语法:from_unixtime(bigint unixtime[, stringformat]) 返回值: string说明: 转化 ...
- Hive时间函数笔记
unix_timestamp()函数: 返回值: bigint说明: 获得当前时区的UNIX时间戳 举例: hive> select unix_timestamp() from dual; 14 ...
- Hadoop3集群搭建之——hive添加自定义函数UDTF (一行输入,多行输出)
上篇: Hadoop3集群搭建之——虚拟机安装 Hadoop3集群搭建之——安装hadoop,配置环境 Hadoop3集群搭建之——配置ntp服务 Hadoop3集群搭建之——hive安装 Hadoo ...
- Hive常用函数的使用
Hive常用函数的使用 文章作者:foochane 原文链接:https://foochane.cn/article/2019062501.html 1 基本介绍 1.1 HIVE简单介绍 Hive ...
- hive日期函数-杂谈(一)
来到广发返现由于历史遗留问题很多时间格式十分杂乱 我将总结一下时间日期的事情 1.hive原生时间函数的功能 2.一些基本业务时间范围的指标的sql案例 3.自定义udf函数让后来人更方便
- Hive 时间操作
Hive 时间转换 UNIX时间戳概念:因为UNIX时间戳只是一个秒数,一个UNIX时间戳在不同时区看来,时间是不同的.如UNIX时间戳0,在0时区看来是1970-01-01 00:00:00,在东八 ...
- Hive sql函数
date: 2018-11-16 19:03:08 updated: 2018-11-16 19:03:08 Hive sql函数 一.关系运算 等值比较: = select 1 from dual ...
- hive常用函数 wordCount--Hive窗口函数1.1.1 聚合开窗函数聚合开窗函数实战
第三天笔记 第三天笔记 SQL练习Hive 常用函数关系运算数值计算条件函数日期函数重点!!!字符串函数Hive 中的wordCount1.1 Hive窗口函数1.1.1 聚合开窗函数聚合开窗函数实战 ...
- C++中的时间函数
C++获取时间函数众多,何时该用什么函数,拿到的是什么时间?该怎么用?很多人都会混淆. 本文是本人经历了几款游戏客户端和服务器开发后,对游戏中时间获取的一点总结. 最早学习游戏客户端时,为了获取最精确 ...
随机推荐
- ORA-02266错误的批量生成脚本解决方案
ORA-02266: unique/primary keys in table referenced by enabled foreign keys这篇博客是很早之前总结的一篇文章,最近导数时使用TR ...
- oracle sql developer 出现 : 适配器无法建立连接问题解决方案 The Network Adapter could not establish the connection
直接上图比较直观 tips one:先看看自己 控制台的 SQLplus 可以登录不 可以直接往下面走 ,如果不可以就现在服务里面找到 Oracle 开头的服务启动就好 实在不会可以百度 注:由于该步 ...
- Select2控件不能自适应的解决办法
$.fn.select2.defaults.set('width', '100%');
- html元素禁用disable or enable
场景说明 ajax提交数据,防止收到服务端相应前用户重复点击. 1.用户点击按钮,禁用当前按钮,发起ajax请求. 2.收到ajax请求,还原当前按钮. html解决方案 参考地址:http://ww ...
- 测试面试话题8:测试人员如何让开发少写bug?
在测试过程中和不同开发合作,往往会发现一些bug都是大多数开发人员常出现的错误,为了帮助开发人员,也减少测试的重复工作量,非常有必要将以往出现的bug做整理,分析原因,让开发知道这些bug, 避免再次 ...
- python接口自动化-post请求2
一.headers 1.以禅道登录为例,模拟登陆,这里需添加请求头headers,可以用fiddler抓包 2.将请求头写成字典格式 h = { "Connection": &qu ...
- shell脚本监控
监控磁盘空间 vim check_disk.sh #!/bin/bash # test common. #warn=$ #err=$ #mount=$ check_val() { /usr/bin/e ...
- Django的ORM那些相关操作
一般操作 看专业的官网文档,做专业的程序员! 必知必会13条 <> all(): 查询所有结果 <> filter(**kwargs): 它包含了与所给筛选条件相匹配的对象 & ...
- docker 容器的启动方式
1.Docker 优势: .更高效利用系统资源:由于容器不需要进行硬件虚拟以及运行完整操作系统等额外开销,Docker 对系统资源的利用率更高.无论是应用执行速度.内存损耗或者文件存储速度,都要比传统 ...
- linux 上 mysql 的使用
1.登录mysql 第一次登录 没有密码 可以直接输入 mysql 有密码可以使用 mysql -u root -p 回车会提示需要输入密码 -u 用户名 -p 密码 这个mysql文件在/us ...