How to calculate the difference between 2 dates in Hive? - Big Data In Real World

How to calculate the difference between 2 dates in Hive?

How to select top N rows in Hive?
October 8, 2021
What is the difference between EXPLODE and LATERAL VIEW EXPLODE in Hive?
October 15, 2021
How to select top N rows in Hive?
October 8, 2021
What is the difference between EXPLODE and LATERAL VIEW EXPLODE in Hive?
October 15, 2021

Comparing 2 dates is quite common when you deal with data. Hive has datediff function to help you compare 2 dates.

Solution

datediff function in Hive takes 2 dates in String type and gives you the difference between the dates.

datediff(string enddate, string startdate)

String dates should be in yyyy-MM-dd format

SELECT datediff('2009-03-01', '2009-02-27') 
2 will be the output

 

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 calculate the difference between 2 dates 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