返回 当前时间

MySQL use now()
Hive use

  1. from_unixtime(unix_timestamp(),'yyyy-MM-dd')
  2. from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss')
  3. --示例:
  4. SELECT from_unixtime(unix_timestamp(),'yyyy-MM-dd') 2018-11-05
  5. SELECT from_unixtime(unix_timestamp(),'yyyyMMdd') 20181105

释义:
unix_timestamp() 返回当前时区的unix时间戳
from_unixtime(bigint unixtime[,string format]) 时间戳转日期函数
to_date(string date)
YEAR()
MONTH()
DAY()
weekofyear() 本年多少周

日期差

datediff(enddate,begindate)
date\_add(date,days) date+days
date\_sub(date,days) date-days

小时差

  1. SELECT
  2. (hour(from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss'))-hour('2018-01-01 12:00:00')+
  3. (datediff(from_unixtime(unix_timestamp(),'yyyy-MM-dd HH:mm:ss'),'2018-01-01 12:00:00'))*24) as hour_dValue