Hive常用函数总结

1.求日期时间差:

datediff(时间A,时间B),输入是字符串类型,因此用单引号'';输出是int类型。
例子:select datediff('2018-06-06','2018-05-06')

结果:31

2.求星期几:pmod()

pmod(datediff(partition_date,'2018-05-06'),7)

3.根据时间戳求对应的日期:

from_unixtime(时间戳)。这里的时间戳包含两种形式:一种是10位,直接作为from_unixtime的输入就好,一类是13位,这时需要除以1000.返回值是'2018-06-02'字样的日期。
from_unixtime(timestamp)

4.获取小时:

hour()
hour(from_unixtime(order_add_timestamp))

5.字符串中查找字符:

instr( string1, string2, start_position,nth_appearance ),
 string1:源字符串,要在此字符串中查找。
 string2:要在string1中查找的字符串 。
 start_position:代表string1 的哪个位置开始查找。
instr(weekday_unavailable,'5')

猜你喜欢

转载自blog.csdn.net/pearl8899/article/details/80399706