How to get the current date and time in Hive? - Big Data In Real World

How to get the current date and time in Hive?

Why do I see 200 tasks in Spark execution?
September 24, 2021
What are applications, jobs, stages and tasks in Spark?
September 29, 2021
Why do I see 200 tasks in Spark execution?
September 24, 2021
What are applications, jobs, stages and tasks in Spark?
September 29, 2021

Pretty simple problem with a simple solution.

Solution

CURRENT_DATE will give the current date and CURRENT_TIMESTAMP will give you the date and time.

0: jdbc:hive2://ms2.hirw.com:2181,wk1.hirw.co> SELECT CURRENT_DATE;
+-------------+--+
|     _c0     |
+-------------+--+
| 2020-11-12  |
+-------------+--+

0: jdbc:hive2://ms2.hirw.com:2181,wk1.hirw.co> SELECT CURRENT_TIMESTAMP;
+--------------------------+--+
|           _c0            |
+--------------------------+--+
| 2020-11-12 18:00:47.827  |
+--------------------------+--+

 

If you want to work with EPOCH time then use unix_timestamp() to get the EPOCH time and use from_unixtime to convert EPOCH to date and time.

0: jdbc:hive2://ms2.hirw.com:2181,wk1.hirw.co> SELECT unix_timestamp();
+-------------+--+
|     _c0     |
+-------------+--+
| 1605204223  |
+-------------+--+

1 row selected (0.133 seconds)

0: jdbc:hive2://ms2.hirw.com:2181,wk1.hirw.co> SELECT from_unixtime(unix_timestamp());
+----------------------+--+
|         _c0          |
+----------------------+--+
| 2020-11-12 18:04:39  |
+----------------------+--+
1 row selected (0.565 seconds)

 

Big Data In Real World
Big Data In Real World
We are a group of Big Data engineers who are passionate about Big Data and related Big Data technologies. We have designed, developed, deployed and maintained Big Data applications ranging from batch to real time streaming big data platforms. We have seen a wide range of real world big data problems, implemented some innovative and complex (or simple, depending on how you look at it) solutions.
How to get the current date and time in Hive?
This website uses cookies to improve your experience. By using this website you agree to our Data Protection Policy.

Hadoop In Real World is now Big Data In Real World!

X