Common date hive sql handler summary

1) date_format function (in accordance with the format finishing date)

  Action: a string format for the specified date format.

SELECT DATE_FORMAT ( ' 2017-01-01 ' , ' yyyy-MM-dd HH: mm: SS ' ); - the date string must meet the format yyyy-MM-dd    

  Results: 2017-01-01 00:00:00

2) date_add, date_sub function (subtraction date)

  Effect of: a date format string plus one day, minus one day.

SELECT DATE_ADD ( ' 2019-01-01 ' , . 1 ); - string must meet the format yyyy-MM-dd    

  Results: 2019-01-02

SELECT DATE_SUB ( ' 2019-01-01 ' , . 1 ); - string must meet the format yyyy-MM-dd 

  Results: 2018-12-31

3) next_day function

  Role: to give a specific date for next week's string of dates of several

SELECT next_date ( ' 2020-01-01 ' , ' Fri ' ); - obtain a first subsequent Friday 2020-01-01

  Results: 2020-01-03

4) last_day function (the last day of the month demand date)

  Role: seeking the last day of the month date

select last_day('2020-01-01');

  Results: select last_day ( '2020-01-01');

5) from_unixtime ( 'bigint stamp', 'pattern') function together with 5,6, used to the date string is not yyyy-MM-dd into the standard yyyy-MM-dd date string

  Effect: the time stamp of a large number, the date string is converted to a specified format

select from_unixtime(1517725479,'yyyy-MM-dd HH:dd:ss');
select from_unixtime(1517725479,'yyyyMMdd');

  Results: 2018-02-04 14:04:39

     20180204

6) unix_timestamp ( 'date string', 'pattern') 5,6 together with, used to the date string is not yyyy-MM-dd into a standard date string is yyyy-MM-dd

  Action: the date stamp converted into the specified format

select unix_timestamp('2020/01/01','yyyy/MM/dd');

  RESULTS: 1577808000

7)current_date()

  Role: get the current date string

select current_date();

  Results: 2020-01-01

8)current_timestamp()

  Role: get the current time string

select current_timestamp();

  Results: 2020-01-0113: 52: 46.018

9) unix_timestamp()

  Role: get the current timestamp

select unix_timestamp();

  RESULTS: 1577858367

Guess you like

Origin www.cnblogs.com/wpbk007/p/12128800.html