Large data, algorithm QQ Communication group: 397173819
Do data mining, can not be separated from the use of various time functions.
In order to avoid forgetting, as well as follow-up various flying blind everywhere, deliberately summed up the hive most commonly used time functions, convenient to their own convenience. 1.unix_timestamp ()
Returns the Unix time stamp for the current time zone
return type: bigint
Hive (TMP) > select Unix_timestamp () from Hive_sum limit 1;
1465875016 2.from_unixtime (bigint unixtime[,string format])
Timestamp Spin Date function
return type: string
Hive (TMP) > select From_unixtime (Unix_timestamp (), ' YyyyMMdd ') from hive_sum limit 1;
20160614 3.unix_timestamp (string date)
Returns the timestamp of the specified date format
return type: bigint
Note: If only the date argument is followed, the form of date must be in the form of ' Yyyy-mm-dd HH:mm:ss '.
Hive (TMP) > select Unix_timestamp (' 2016-06-01 ') from hive_sum limit 1;
Null
Hive (TMP) > select Unix_timestamp (' 2016-06-01 00:00:00 ') from hive_sum limit 1;
1464710400 4.unix_timestamp (string date,string pattern)
Returns the timestamp of the specified date format
return type: bigint
Hive (TMP) > select Unix_timestamp (' 2016-06-01 ', ' yyyyMMdd ') from hive_sum limit 1;
1449331200 5.to_date (string date)
Returns the date part in a Time field
return type: string
Hive (TMP) > select To_date (' 2016-06-01 00:00:00 ') from hive_sum limit 1;
2016-06-01 6.year (string date)
Returns the year in the Time field
return type: int
Hive (TMP) > select year (' 2016-06-01 00:00:00 ') from hive_sum limit 1;
2016 7.month (string date)
Returns the month in the Time field
return type: int
Hive (TMP) > select month (' 2016-06-01 ') from hive_sum limit 1;
6 8.day (string date)
Returns the day in the Time field
return type: int
Hive (TMP) > select Day (' 2016-06-01 ') from hive_sum limit 1;
1 9.weekofyear (string date)
Return Time field is the number of weeks of the year
return type: int
Hive (TMP) > select WeekOfYear (' 2016-06-01 ') from hive_sum limit 1;
10.datediff (String enddate,string begindate)
Returns the number of days between EndDate and Begindate
return type: int
Hive (TMP) > select DateDiff (' 2016-06-01 ', ' 2016-05-01 ') from hive_sum limit 1;
11.date_add (String date,int days)
Returns the date of day added days
return type: string
Hive (TMP) > select Date_add (' 2016-06-01 ') from hive_sum limit 1;
2016-06-16 12.date_sub (string date,int days)
Return date to reduce days after
return type: string
Hive (TMP) > select Date_sub (' 2016-06-01 ') from hive_sum limit 1;
2016-05-17