Summary of date functions in hive

Source: Internet
Author: User
Summary of date functions in--hive:
--1. Time stamp function
--Date-time stamp: number of seconds from 1970-01-01 00:00:00 UTC to a specified time
Select Unix_timestamp (); --Get the current time zone's Unix timestamp
Select Unix_timestamp (' 2017-09-15 14:23:00 ');
Select Unix_timestamp (' 2017-09-15 14:23:00 ', ' yyyy-mm-dd HH:mm:ss ');
Select Unix_timestamp (' 20170915 14:23:00 ', ' yyyyMMdd HH:mm:ss ');

--time stamp turn date
Select From_unixtime (1505456567);
Select From_unixtime (1505456567, ' yyyyMMdd ');
Select From_unixtime (1505456567, ' yyyy-mm-dd HH:mm:ss ');
Select From_unixtime (Unix_timestamp (), ' yyyy-mm-dd HH:mm:ss '); --Get the system current time

--2. Get Current Date: current_date
Hive> Select Current_date from dual
2017-09-15

--3. Date time to date: To_date (string timestamp)
Hive> Select To_date (' 2017-09-15 11:12:00 ') from dual;
2017-09-15

--3. Get year/month/day/hour/minute/sec/week in date
With Dtime as (select From_unixtime (Unix_timestamp (), ' Yyyy-mm-dd HH:mm:ss ') as DT)
Select year (DT), month (DT), day (DT), hour (DT), Minute (DT), second (DT), weekofyear (DT)
From Dtime

--4. Calculate the number of days between two dates: DateDiff
Hive> Select DateDiff (' 2017-09-15 ', ' 2017-09-01 ') from dual;
14

--5. Date increase and Decrease: date_add/date_sub (string Startdate,int days)
Hive> Select Date_add (' 2017-09-15 ', 1) from dual;
2017-09-16
Hive> Select Date_sub (' 2017-09-15 ', 1) from dual;
2017-09-14

--Other date functions
Query current system time (including milliseconds): Current_timestamp;
Check the day of the Month: DayOfMonth (current_date);
Month End: Last_day (current_date)
1th Day of the Month: Date_sub (Current_date,dayofmonth (current_date)-1)

1th Day of next month: Add_months (date_sub (Current_date,dayofmonth (current_date)-1), 1)


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.