Hive 时间函数
--Hive中日期函数总结:
--1.时间戳函数
--日期转时间戳:从1970-01-01 00:00:00 UTC到指定时间的秒数
select unix_timestamp(); --获得当前时区的UNIX时间戳
select unix_timestamp('2017-09-15 14:23:00');
select unix_timestamp('2017-09-15 14:23:00','yyyy-MM-dd HH:mm:ss');
select unix_timestamp('20170915 14:23:00','yyyyMMdd HH:mm:ss');
--时间戳转日期
select from_unixtime(1505456567);
select from_unixtime(1505456567,'yyyyMMdd');
select from_unixtime(1505456567,'yyyy-MM-dd HH:mm:ss');
select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss'); --获取系统当前时间
--2.获取当前日期: current_date
hive> select current_date from dual
2017-09-15
--3.日期时间转日期:to_date(string timestamp)
hive> select to_date('2017-09-15 11:12:00') from dual;
2017-09-15
--3.获取日期中的年/月/日/时/分/秒/周
with dtime as(select from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss') as dt)
select year(dt),month(dt),day(dt),hour(dt),minute(dt),second(dt),weekofyear(dt)
from dtime
--4.计算两个日期之间的天数: datediff
hive> select datediff('2017-09-15','2017-09-01') from dual;
14
--5.日期增加和减少: date_add/date_sub(string startdate,int days)
hive> select date_add('2017-09-15',1) from dual;
2017-09-16
hive> select date_sub('2017-09-15',1) from dual;
2017-09-14
--其他日期函数
查询当前系统时间(包括毫秒数): current_timestamp;
查询当月第几天: dayofmonth(current_date);
月末: last_day(current_date)
当月第1天: date_sub(current_date,dayofmonth(current_date)-1)
下个月第1天: add_months(date_sub(current_date,dayofmonth(current_date)-1),1)
转自:https://blog.csdn.net/qq646748739/article/details/77997276
相关文章
- hive时间函数详解
- Sql Server datetime 和 smalldatetime时间函数的区别
- 利用IAR Timeline工具测试delay函数执行时间
- fopen 打开网址 设置php.ini,[教程] DreamHost修改php.ini来打开allow_url_fopen函数以支持采集…
- mysql取得当前时间的函数_oracle数据库时间戳函数
- mysql 时间戳格式化函数from_unixtime使用说明详解数据库
- javascript 时间格式输出FormatDate函数详解编程语言
- 给file_get_contents函数设置超时时间详解编程语言
- 函数利用MySQL平均时间函数实现高效数据分析(mysql平均时间)
- Linux 内核时间函数探索之旅(linux内核时间函数)
- Oracle中的函数:功能丰富的数据处理工具(oracle什么是函数)
- MySQL中调用存储过程函数的方法(mysql过程调用函数)
- 利用Oracle中的日期时间函数实现完美时间控制(oracle日期时间函数)
- Oracle的Mod函数详解及应用示例(oracle的mod)
- MySQL中灵活使用开窗函数节约时间(mysql开窗函数)
- 深入理解 Linux 时间戳函数(linux时间戳函数)
- 执行时间Linux下探究查看函数执行时长分析(linux如何查看函数)
- 化自定义函数研究及实践(mysql中custom)
- Oracle中构建强大数据转换的转换函数(oracle中的转换函数)
- Oracle数据库中的炸裂函数及其应用(oracle中炸裂函数)
- 在Oracle中使用小写函数实现数据处理(oracle中小写函数)
- PHP产生随机字符串函数
- 广告代码静态化js通用函数
- mysql的日期和时间函数
- MySQL获得当前日期时间的函数小结
- asp中日期时间函数介绍
- PHP输出时间差函数代码
- 使用C语言中的time函数获取系统时间
- php中用date函数获取当前时间有误的解决办法
- SQLite3中的日期时间函数使用小结
- Javascript学习笔记之函数篇(四):arguments对象