hive 日期函数

1.unix时间戳转时间函数

?


1

2

3

4

5

6

7

8

9

10

语法: from_unixtime(bigintunixtime[, string format])

返回值: string

说明: 转化UNIX时间戳(从1970-01-01 00:00:00 UTC到指定时间的秒数)到当前时区的时间格式

举例:

hive>selectfrom_unixtime(1323308943,‘yyyyMMdd’)fromdual;

20111208

2.获取当前时区的unix时间戳

?


1

2

3

4

5

6

7

8

9

10

语法: unix_timestamp()

返回值:bigint

说明: 获得当前时区的UNIX时间戳

举例:

hive>selectunix_timestamp()fromdual;

1323309615

3.时间转unix时间戳

?


1

2

3

4

5

6

7

8

9

10

11

日期转UNIX时间戳函数: unix_timestamp语法:   unix_timestamp(stringdate)

返回值:  bigint

说明: 转换格式为“yyyy-MM-dd HH:mm:ss“的日期到UNIX时间戳。如果转化失败,则返回0。

举例:

hive>  selectunix_timestamp(’2011-12-07 13:01:03′)fromdual;

1323234063

?


1

2

3

4

5

6

7

8

9

10

11

指定格式日期转UNIX时间戳函数: unix_timestamp语法:   unix_timestamp(stringdate, string pattern)

返回值:  bigint

说明: 转换pattern格式的日期到UNIX时间戳。如果转化失败,则返回0。

举例:

hive>  selectunix_timestamp(’20111207 13:01:03′,’yyyyMMdd HH:mm:ss’)fromdual;

1323234063

4.日期时间转日期函数

?


1

2

3

4

5

6

7

8

9

10

语法: to_date(stringtimestamp)

返回值: string

说明: 返回日期时间字段中的日期部分。

举例:

hive>selectto_date(’2011-12-08 10:03:01′)fromdual;

2011-12-08

5.获取年份的函数

?


1

2

3

4

5

6

7

8

9

10

11

12

13

14

语法:year(stringdate)

返回值:int

说明: 返回日期中的年。

举例:

hive>selectyear(’2011-12-08 10:03:01′)fromdual;

2011

hive>selectyear(’2012-12-08′)fromdual;

2012

6.获取月份的函数

?


1

2

3

4

5

6

7

8

9

10

11

12

13

14

语法:month(stringdate)

返回值:int

说明: 返回日期中的月份。

举例:

hive>selectmonth(’2011-12-08 10:03:01′)fromdual;

12

hive>selectmonth(’2011-08-08′)fromdual;

8

7.获取天的函数

?


1

2

3

4

5

6

7

8

9

10

11

12

13

14

语法:day(stringdate)

返回值:int

说明: 返回日期中的天。

举例:

hive>selectday(’2011-12-08 10:03:01′)fromdual;

8

hive>selectday(’2011-12-24′)fromdual;

24

8.获取小时的函数

?


1

2

3

4

5

6

7

8

9

10

语法:hour(stringdate)

返回值:int

说明: 返回日期中的小时。

举例:

hive>selecthour(’2011-12-08 10:03:01′)fromdual;

10

9.获取分数的函数

?


1

2

3

4

5

6

7

8

9

10

语法:minute(stringdate)

返回值:int

说明: 返回日期中的分钟。

举例:

hive>selectminute(’2011-12-08 10:03:01′)fromdual;

3

10.获取秒的函数

?


1

2

3

4

5

6

7

8

9

10

语法:second(stringdate)

返回值:int

说明: 返回日期中的秒。

举例:

hive>selectsecond(’2011-12-08 10:03:01′)fromdual;

1

11.获取日期在当前的周数

?


1

2

3

4

5

6

7

8

9

10

语法: weekofyear (stringdate)

返回值:int

说明: 返回日期在当前的周数。

举例:

hive>selectweekofyear(’2011-12-08 10:03:01′)fromdual;

49

12.日期比较函数

?


1

2

3

4

5

6

7

8

9

10

语法: datediff(string enddate, string startdate)

返回值:int

说明: 返回结束日期减去开始日期的天数。

举例:

hive>selectdatediff(’2012-12-08′,’2012-05-09′)fromdual;

213

13.日期增加函数

?


1

2

3

4

5

6

7

8

9

10

语法: date_add(string startdate,intdays)

返回值: string

说明: 返回开始日期startdate增加days天后的日期。

举例:

hive>selectdate_add(’2012-12-08′,10)fromdual;

2012-12-18

14.日期减少函数

?


1

2

3

4

5

6

7

8

9

10

语法: date_sub (string startdate,intdays)

返回值: string

说明: 返回开始日期startdate减少days天后的日期。

举例:

hive>selectdate_sub(’2012-12-08′,10)fromdual;

2012-11-28

时间: 2024-08-10 23:16:13

hive 日期函数的相关文章

hive日期函数-Demo(二)

需求:某资产近一个月的资产值 比如:今天是2018年2月28日,近一个月若是按照自然月来算,那么是2018年2月1日至2018年2月28日.最终需要的日期格式为:yyyyMMdd. 当日时间戳 unix_timestamp() 方法可得到当前时间的时间戳. 上月今日 使用 add_months(日期,N) 函数可将日期往前.往后推N个月.主要有两种格式: add_months('yyyy-MM-dd hh:mm:ss',N),add_months('yyyy-MM-dd',N).N为正往后推,N

hive日期转换函数2

转自大神 http://www.oratea.net/?p=944 无论做什么数据,都离不开日期函数的使用. 这里转载一下Hive的日期函数的使用,写的相当完整. 日期函数UNIX时间戳转日期函数: from_unixtime语法:from_unixtime(bigint unixtime[, string format]) 返回值: string说明: 转化UNIX时间戳(从1970-01-01 00:00:00 UTC到指定时间的秒数)到当前时区的时间格式举例:hive> select fr

hive函数总结-日期函数

获取当前UNIX时间戳函数: unix_timestamp语法: unix_timestamp() 返回值: 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[,

Hive的日期函数

1.unix时间戳转时间函数 语法: from_unixtime(bigint unixtime[, string format]) 返回值: string 说明: 转化UNIX时间戳(从1970-01-01 00:00:00 UTC到指定时间的秒数)到当前时区的时间格式 举例: hive> select from_unixtime(1323308943,'yyyyMMdd') from dual; 20111208 2.获取当前时区的unix时间戳 语法: unix_timestamp() 返

orcale和hive常用函数对照表(?代表未证实)

函数分类 oracle hive 说明 字符函数 upper('coolszy') upper(string A) ucase(string A) 将文本字符串转换成字母全部大写形式 lower('KUKA') lower(string A) lcase(string A) 将文本字符串转换成字母全部小写形式 initcap('kuKA aBc') 无  将每个单词的首字母大写,其他位置的字母小写 concat('Hello',' world') concat(string A, string 

Hive 时间函数总结【转】

1.日期函数UNIX时间戳转日期函数: from_unixtime语法:from_unixtime(bigint unixtime[, stringformat]) 返回值: string说明: 转化UNIX时间戳(从1970-01-0100:00:00 UTC到指定时间的秒数)到当前时区的时间格式举例:hive> select from_unixtime(1323308943,'yyyyMMdd') from dual;20111208 2.获取当前UNIX时间戳函数: unix_timest

sql的基础语句-单行函数,dual,数字函数,日期函数,表连接,集合运算,分组报表,单行子查询,多行子查询

3. 单行函数 3.1 转换函数 select ascii('A'),chr(65) from dual; select to_char(1243123),1231451 from dual;靠左边的就是字符串,靠右边的就是数字 select to_char(123512a121) from dual;   --错误的写法,没有引号表示数字,但是数字里面包含了字母,不合法的输入值 select to_number('123141211') from dual; select to_number(

SQL-数学、字符串、时间日期函数和类型转换

--数学函数 --ABS绝对值,select ABS(-99)--ceiling取上限,select CEILING(4.5)--floor去下限select FLOOR(4.5)--power 几次方,select POWER(2,2)--round四舍五入,select round (6.45,1)--sqrt开平方select SQRT(9)--square平方select SQUARE(5) --字符串函数--ASCII 返回字符串最左边的字符ascii码select ASCII('na

JS日期函数

JS的日期函数有以下几个: getFullYear(); //获取当前年 getMonth(); //获取当前月,需要加1,而且只有一位数字,如果小于10需要前面加0 getDate(); //获取当前日,只有一位数字,如果小于10需要前面加0 getTime();//返回从 1970 年 1 月 1 日至今的毫秒数. toUTCString();//将当日的日期(根据 UTC)转换为字符串. getDay();//返回星期数 getHours();//返回小时 getMinutes();//返