Hive date functions, Hive date functions

Source: Internet
Author: User

Hive date functions, Hive date functions
1. unix timestamp to Time Function

Syntax: from_unixtime (bigint unixtime [, string format]) Return Value: string Description: converts a UNIX timestamp (from 00:00:00 UTC to the specified time in seconds) to the current time zone for example: hive> select from_unixtime (1323308943, 'yyyymmdd') from dual; 20111208
2. Obtain the unix timestamp of the current time zone
Syntax: unix_timestamp () Return Value: bigint Description: obtains the UNIX timestamp of the current time zone. Example: hive> select unix_timestamp () from dual; 1323309615

3. Time to unix Timestamp
Date to UNIX timestamp function: unix_timestamp Syntax: unix_timestamp (string date) Return Value: bigint Description: conversion format: "yyyy-MM-dd HH: mm: ss "date to UNIX timestamp. If the conversion fails, 0 is returned. Example: hive> select unix_timestamp ('2017-12-07 13:01:03 ') from dual; 2011
Specify the format date to UNIX timestamp function: unix_timestamp Syntax: unix_timestamp (string date, string pattern) Return Value: bigint Description: Convert the date to UNIX timestamp in pattern format. If the conversion fails, 0 is returned. Example: hive> select unix_timestamp ('2017 13:01:03 ', 'yyyymmdd HH: mm: ss') from dual; 20111207


4. Date-time to date functions
Syntax: to_date (string timestamp) Return Value: string Description: return the date part of the date and time field. Example: hive> select to_date ('2017-12-08 10:03:01 ') from dual; 2011-12-08

5. Get the year Function
Syntax: year (string date) Return Value: int Description: returns the year from the date. Example: hive> select year ('2017-12-08 10:03:01 ') from dual; 2011 hive> select year ('2017-12-08') from dual; 2011

6. Obtain the month function.
Syntax: month (string date) Return Value: int Description: return the month in the date. Example: hive> select month ('2017-12-08 10:03:01 ') from dual; 12 hive> select month ('2017-08-08') from dual; 8

7. Get the function of the day
Syntax: day (string date) Return Value: int Description: return the day in the date. Example: hive> select day ('2017-12-08 10:03:01 ') from dual; 8 hive> select day ('2017-12-24') from dual; 24

8. Get the hour Function
Syntax: hour (string date) Return Value: int Description: return the hour in the date. Example: hive> select hour ('2017-12-08 10:03:01 ') from dual; 10

9. Function for obtaining scores
Syntax: minute (string date) Return Value: int Description: returns the minute in the date. Example: hive> select minute ('2017-12-08 10:03:01 ') from dual; 3

10. Get the second function
Syntax: second (string date) Return Value: int Description: returns the second in the date. Example: hive> select second ('2017-12-08 10:03:01 ') from dual; 1
11. Get the number of days in the current week
Syntax: weekofyear (string date) Return Value: int Description: return the number of weeks of the current date. Example: hive> select weekofyear ('2017-12-08 10:03:01 ') from dual; 49

12. Date comparison functions
Syntax: datediff (string enddate, string startdate) Return Value: int Description: return the end date minus the number of days of the start date. Example: hive> select datediff ('2017-12-08', '2017-05-09 ') from dual; 2012

13. Date addition Function
Syntax: date_add (string startdate, int days) Return Value: string Description: return the date after startdate is added to days. Example: hive> select date_add ('2017-12-08', 10) from dual; 2012-12-18

14. Date reduction functions
Syntax: date_sub (string startdate, int days) Return Value: string Description: return the date after startdate minus days. Example: hive> select date_sub ('2017-12-08', 10) from dual; 2012-11-28

Timestamp is stored in hive as a string (with decimal point). to convert the timestamp field to time, use the following function:

The timestamp is a 10-digit integer with no decimals;
See where you are using it. If you are using date ("Y-m-d", hive) in PHP, you can directly convert it if you use formart_date in Mysql.
 
In Hive, how does one convert the timestamp of the string class to a date?

You can add 7200 seconds or within the range of 7200 seconds.
 

Related Article

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.