温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

hive日期函数有哪些

发布时间:2021-12-09 09:26:55 来源:亿速云 阅读:175 作者:小新 栏目:云计算

这篇文章将为大家详细讲解有关hive日期函数有哪些,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

1.日期函数 to_date(string expr)

返回类型:string

描述:返回时间字符串日期部分

to_date(expr) - Extracts the date part of the date or datetime expression expr

实例:

hive> select to_date('2014-09-16 15:50:08.119') from default.dual;

2014-09-16


2.年份函数 year(string expr)

返回类型:int

描述:返回时间字符串年份数字

year(date) - Returns the year of date

实例:

hive> select year('2014-09-16 15:50:08.119') from default.dual;

2014


3.月份函数 month(string expr)

返回类型:int

描述:返回时间字符串月份数字

month(date) - Returns the month of date

实例:

hive> select month('2014-09-16 15:50:08.119') from default.dual;

09


4.天函数 day(string expr)

返回类型:int

描述:返回时间字符串的天

day(date) - Returns the date of the month of date

实例:

hive> select day('2014-09-16 15:50:08.119') from default.dual;

16


5.小时函数 hour(string expr)

返回类型:int

描述:返回时间字符串小时数字

hour(date) - Returns the hour of date

实例:

hive> select hour('2014-09-16 15:50:08.119') from default.dual;

15


6.分钟函数 hour(string expr)

返回类型:int

描述:返回时间字符串分钟数字

minute(date) - Returns the minute of date

实例:

hive> select minute('2014-09-16 15:50:08.119') from default.dual;

50

7.秒函数 second(string expr)

返回类型:int

描述:返回时间字符串分钟数字

second(date) - Returns the second of date

实例:

hive> select second('2014-09-16 15:50:08.119') from default.dual;

08

8.日期增加函数 date_add(start_date, num_days)

返回类型:string

描述:返回增加num_days 天数的日期(负数则为减少)

date_add(start_date, num_days) - Returns the date that is num_days after start_date.

实例:

hive>select date_add('2014-09-16 15:50:08.119',10) from default.dual;

2014-09-26

hive>select date_add('2014-09-16 15:50:08.119',-10) from default.dual;

2014-09-06

9.日期减少函数 date_sub(start_date, num_days)

返回类型:string

描述:返回num_days 天数之前的日期(负数则为增加)

date_sub(start_date, num_days) - Returns the date that is num_days before start_date.

实例:

hive>select date_sub('2014-09-16 15:50:08.119',10) from default.dual;

2014-09-06

hive>select date_sub('2014-09-16 15:50:08.119',-10) from default.dual;

2014-09-26

10.周期函数 weekofyear(start_date, num_days)

返回类型:int

描述:返回当前日期位于本年的周期 一周一个周期

weekofyear(date) - Returns the week of the year of the given date. A week is considered to start on a Monday and week 1 is the first week with >3 days.

实例:

hive>select weekofyear('2014-09-16 15:50:08.119') from default.dual;

38

11.日期比较函数 weekofyear(start_date, num_days)

返回类型:string

描述:返回2个时间的日期差

datediff(date1, date2) - Returns the number of days between date1 and date2

date1-date2

实例:

hive>select datediff('2014-09-16 15:50:08.119','2014-09-15') from default.dual;

关于“hive日期函数有哪些”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI