Hive 时间函数

摘要:
--配置单元中日期函数的摘要:--1.时间戳函数--日期到时间戳:从1970-01-0100:00UTC到指定时间selectunix_timestamp()的秒数;--获取当前时区selectunix_timestamp的UNIX时间戳('2017-09-1514:23:00');selectunix_时间戳('2017-09-1514:23:00','yyyy-MM-ddHH:

--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 时间函数》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Vue 返回上一页,记住上一页的数据ASP.NET(c#)实现重定向的三种方法的总结下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Open SQL详解

读取数据SELECT. 262 读取单行... 263 DISTINCT. 263 读取多行... 264 列别名... 264 存储到指定变量中... 264 SELECT * INTO….. 265 追加读取APPENDING.. 265 CORRESPONDING FIELDS OF [WA/TABLE]….. 266 [PACKAGE SIZE...

select下拉框的数据回显

需求描述:select框,下拉后又很多的选项,选择一个,根绝后台代码做查询,完成之后,页面上的select框还是之前选的那个值 解决思路:select本质就是 value和text一一对应,根据你的select下拉菜单,可以在代码中看看value具体是什么,text是什么,比如说value是对应的id而text是对应的name,然后后台根绝选择的内容查询的...

ORACLE权限管理—创建只读账号

创建只读用户:grant connect to user; grant create session to user; 1.创建角色 CREATE ROLE SELECT_ROLE 2.给角色分配权限 grant SELECT ANY DICTIONARY to SELECT_ROLE; grant SELECT ANY TABLE to SELECT_R...

oracle 中的truncate 和delete

一、查询表大小,块多少语句 Select SEGMENT_Name,BYTES,BLOCKS,Extents From dba_segments Where segment_name In('BAI_NEW_SESSION_HISTORY2') order by segment_name; (2)查表空间 Select Tablespace_Name,...

sql jion

    A Visual Explanation of SQL Joins I thought Ligaya Turmelle's post on SQL joins was a great primer for novice developers. Since SQL joins appear to be set-based, the use of V...

windows计划任务+批处理文件实现oracle数据库的定时备份与恢复

1.备份:PS:2014-1-15 如果导出的dmp数据文件不大的话,就直接每天导出好了,不要只保存七天的数据。然后顶起通过winrar对文件进行打包,我发现dmp文件的压缩包还是很高的。 那么就需要考虑在导出的dmp文件末尾加上日期了。bat脚本里面有date和time的函数,通过以下函数我们就可以得到想要的日期了。如果要求日期是以"-"结束,需要设定日...