Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the hive time date function

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to use the hive time and date function. I hope you will get something after reading this article. Let's discuss it together.

1. Hive gets the current date and time:

1.1) get the current date:

Select current_date ()

1.2) get the current date and time:

Select current_timestamp ()

1.3) hive acquires the current timestamp:

Select unix_timestamp ()

1.4) timestamp date:

Select from_unixtime (1517725479)

1.5) date is converted to unix timestamp:

Select to_nuix_timestamp ('2017-01-01 12-12-12-12-15-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-12-1-01-01-12-12-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1,' 2017-01-1-1, 12-1-1-1-1-1-1-1-1-1-1

1.6) hive acquires the current time:

Select from_unixtime (unix_timestamp (), 'yyyy-MM-dd HH:dd:ss')

2. Hive automatically calculates other dates (yesterday, today):

Date addition and subtraction function in hive: date_add (start_date,num_days)

2.1) get yesterday's date:

Select date_add (from_unixtime (unix_timestamp (), 'yyyy-MM-dd'),-1)

Select date_sub (from_unixtime (unix_timestamp (), 'yyyy-MM-dd'), 1)

2.2) get tomorrow's date:

Select date_add (from_unixtime (unix_timestamp (), 'yyyy-MM-dd'), 1)

Select date_sub (from_unixtime (unix_timestamp (), 'yyyy-MM-dd'),-1)

3. Hive obtains the difference between two dates (the difference is the number of days):

Datediff (date1,date2): date1 is greater than date2, and the return value is positive; otherwise, the return value is negative.

Select datediff (from_unixtime (unix_timestamp (), 'yyyy-MM-dd'), date_add (from_unixtime (unix_timestamp (),' yyyy-MM-dd'),-10))

Select datediff (from_unixtime (unix_timestamp (), 'yyyy-MM-dd'), date_add (from_unixtime (unix_timestamp (),' yyyy-MM-dd'), 10))

4. String conversion time (string must be in yyyy-MM-dd format)

Select to_date ('2017-01-01 12 purge 12')

5. Date, time stamp, string type format output standard time format:

Select date_format (current_timestamp (), 'yyyy-MM-dd HH:mm:ss')

Select date_format (current_date (), 'yyyyMMdd')

Select date_format ('2017-01-01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01 / 01

6. Utc time conversion:

Select from_utc_timestamp (current_timestamp (), 8)

Select to_utc_timestamp (current_timestamp (), 8)

After reading this article, I believe you have a certain understanding of "how to use the hive time and date function". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report