hive函数总结-日期函数
2016-02-16 18:13
253 查看
获取当前UNIX时间戳函数: unix_timestamp语法: unix_timestamp()
返回值: bigint
说明: 获得当前时区的UNIX时间戳
举例:
日期函数UNIX时间戳转日期函数: from_unixtime
语法:from_unixtime(bigint unixtime[, string format])
返回值: string
说明: 转化UNIX时间戳(从1970-01-01 00:00:00 UTC到指定时间的秒数)到当前时区的时间格式
举例:
日期转UNIX时间戳函数: unix_timestamp语法:unix_timestamp(string date)
返回值:bigint
说明: 转换格式为“yyyy-MM-dd HH:mm:ss“的日期到UNIX时间戳。如果转化失败,则返回0。
举例:
指定格式日期转UNIX时间戳函数: unix_timestamp语法: unix_timestamp(string date, string pattern)
返回值: bigint
说明: 转换pattern格式的日期到UNIX时间戳。如果转化失败,则返回0。
举例:
日期时间转日期函数: to_date
语法: to_date(string timestamp)
返回值: string
说明: 返回日期时间字段中的日期部分。
举例:
日期转年函数: year
语法: year(string date)
返回值: int
说明: 返回日期中的年。
举例:
日期转月函数: month
语法: month (string date)
返回值: int
说明: 返回日期中的月份。
举例:同上
日期转天函数: day
语法: day (string date)
返回值: int
说明: 返回日期中的天。
举例:同上
日期转小时函数: hour
语法: hour (string date)
返回值: int
说明: 返回日期中的小时。
举例:同上
日期转分钟函数: minute
语法: minute (string date)
返回值: int
说明: 返回日期中的分钟。
举例:同上
日期转秒函数: second
语法: second (string date)
返回值: int
说明: 返回日期中的秒。
举例:同上
日期转周函数: weekofyear
语法: weekofyear (string date)
返回值: int
说明: 返回日期在当前的周数。
举例:
日期比较函数: datediff
语法: datediff(string enddate, string startdate)
返回值: int
说明: 返回结束日期减去开始日期的天数。
举例:
日期增加函数: date_add
语法: date_add(string startdate, int days)
返回值: string
说明: 返回开始日期startdate增加days天后的日期。
举例:
日期减少函数: date_sub语法: date_sub (string startdate, int days)
返回值: string
说明: 返回开始日期startdate减少days天后的日期。
举例:
返回值: bigint
说明: 获得当前时区的UNIX时间戳
举例:
hive> select unix_timestamp() from dual; OK 1455616811 Time taken: 0.785 seconds, Fetched: 1 row(s)
日期函数UNIX时间戳转日期函数: from_unixtime
语法:from_unixtime(bigint unixtime[, string format])
返回值: string
说明: 转化UNIX时间戳(从1970-01-01 00:00:00 UTC到指定时间的秒数)到当前时区的时间格式
举例:
hive> select from_unixtime(1455616811,'yyyyMMdd') from dual; OK 20160216 Time taken: 0.221 seconds, Fetched: 1 row(s)
日期转UNIX时间戳函数: unix_timestamp语法:unix_timestamp(string date)
返回值:bigint
说明: 转换格式为“yyyy-MM-dd HH:mm:ss“的日期到UNIX时间戳。如果转化失败,则返回0。
举例:
hive> select unix_timestamp('2016-02-16 14:02:03') from dual; OK 1455602523 Time taken: 0.265 seconds, Fetched: 1 row(s)
指定格式日期转UNIX时间戳函数: unix_timestamp语法: unix_timestamp(string date, string pattern)
返回值: bigint
说明: 转换pattern格式的日期到UNIX时间戳。如果转化失败,则返回0。
举例:
hive> select unix_timestamp('20160216 14:02:03','yyyyMMdd HH:mm:ss') from dual; OK 1455602523 Time taken: 0.21 seconds, Fetched: 1 row(s)
日期时间转日期函数: to_date
语法: to_date(string timestamp)
返回值: string
说明: 返回日期时间字段中的日期部分。
举例:
hive> select to_date('2016-02-16 14:02:03') from dual; OK 2016-02-16 Time taken: 0.222 seconds, Fetched: 1 row(s)
日期转年函数: year
语法: year(string date)
返回值: int
说明: 返回日期中的年。
举例:
hive> select year('2016-02-16 14:02:03') from dual; OK 2016 Time taken: 0.255 seconds, Fetched: 1 row(s)
hive> select year('2016-02-16') from dual; OK 2016 Time taken: 0.325 seconds, Fetched: 1 row(s)
日期转月函数: month
语法: month (string date)
返回值: int
说明: 返回日期中的月份。
举例:同上
日期转天函数: day
语法: day (string date)
返回值: int
说明: 返回日期中的天。
举例:同上
日期转小时函数: hour
语法: hour (string date)
返回值: int
说明: 返回日期中的小时。
举例:同上
日期转分钟函数: minute
语法: minute (string date)
返回值: int
说明: 返回日期中的分钟。
举例:同上
日期转秒函数: second
语法: second (string date)
返回值: int
说明: 返回日期中的秒。
举例:同上
日期转周函数: weekofyear
语法: weekofyear (string date)
返回值: int
说明: 返回日期在当前的周数。
举例:
hive> select weekofyear('2016-02-16') from dual; OK 7 Time taken: 0.213 seconds, Fetched: 1 row(s)
日期比较函数: datediff
语法: datediff(string enddate, string startdate)
返回值: int
说明: 返回结束日期减去开始日期的天数。
举例:
hive> select datediff('2015-12-20','2016-02-15') from dual; OK -57 Time taken: 0.34 seconds, Fetched: 1 row(s)
日期增加函数: date_add
语法: date_add(string startdate, int days)
返回值: string
说明: 返回开始日期startdate增加days天后的日期。
举例:
hive> select date_add('2015-12-08',10) from dual; OK 2015-12-18 Time taken: 0.289 seconds, Fetched: 1 row(s)
日期减少函数: date_sub语法: date_sub (string startdate, int days)
返回值: string
说明: 返回开始日期startdate减少days天后的日期。
举例:
hive> select date_sub('2015-12-08',10) from dual; OK 2015-11-28 Time taken: 0.249 seconds, Fetched: 1 row(s)
相关文章推荐
- Windows自带的磁盘填充命令
- 谷歌的HTML / CSS规范指南
- 使用Wireshark捕捉USB通信数据
- iOS开发之网络编程--使用NSURLConnection实现文件上传
- 【 bzoj 1444 】 [Jsoi2009]有趣的游戏 - AC自动机+矩阵乘法
- SecureCRT 常用技巧
- SwipeRefreshLayout的升级版RefreshLayout
- Quartz在Spring中动态设置cronExpression (spring设置动态定时任务)
- 记我的工作第一天
- sql server 笔记
- 【转载】用平常语言介绍神经网络
- 设计模式之原型模式
- 一个后端的前端学习之旅——4.第一个demo上线以及关于前端框架我的看法
- javascript dom编程艺术阅读笔记
- Xcode预处理命令、控制台调试命令、 iOS事件拦截
- js 代码的优化 ,完全是照搬,不过挺好使
- Struct2_使用Ajax调用Action方法并返回值
- 移动端开发干货,移动页面性能优化(转)
- Socket send函数和recv函数详解
- vagrant学习笔记 - Vagrantfile