Summary of hive time function

Source: Internet
Author: User
Tags string format

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.