Adding and Substracting Days to a Date – Apache Hive & Impala

We addressed in the previous post that “Date” is the most significant column that helps to explain patterns, trends and even business. From diagnostic analysis to prescriptive analysis and from descriptive analysis to prescriptive analysis, “Date/Time” plays a vital role.

We will need to equate the data for the present date with the data for the historical date. Or we may need to estimate the business on the basis of data from the historic date. Date functions help in such scenarios.

This article aims to let you know how to add and substract days to date column in Apache Hive.

  • Note: The below specified functions are common in both Apache Hive & Apache Impala.

DATE_ADD
Adds a number of days to given date.

DATE_SUB
Substracts a number of days to given date.

Examples: (Click here for sample data)
dateadd_substract

However, if you provide a negative value to Date_Add function, it will be equal to Date_Sub. Refer to the following example.

positivenegativevalues

Hope you liked this post.

Please click on the follow button to receive updates on latest posts.

4 comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s