Adding and Substracting Months to a Date – Apache Hive & Apache 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 months to date column in Apache Hive.

  • Note: The below specified function is common in both Apache Hive & Apache Impala.

ADD_MONTHS:
This function returns the date after adding or substracting the number of months provided for a given date.

Example: (Click here for the sample dataset)
SELECT ADD_MONTHS(date1, 3) FROM DateTest;
SELECT ADD_MONTHS(date2,-3) FROM DateTest;

month add and substract

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