Hive provides a set of built-in functions for performing arithmetic operations on date and time values. Here are some of the common date arithmetic functions in Hive:
- date_add(date, int days) – This function adds a specified number of days to the given date and returns the resulting date.
Example: SELECT date_add(‘2022-03-05’, 7); returns 2022-03-12
- date_sub(date, int days) – This function subtracts a specified number of days from the given date and returns the resulting date.
Example: SELECT date_sub(‘2022-03-05’, 7); returns 2022-02-26
- datediff(date1, date2) – This function returns the number of days between two dates.
Example: SELECT datediff(‘2022-03-05’, ‘2022-03-01’); returns 4
add_months() that can be used to add a specified number of months to a date.
The syntax for the add_months() function is as follows: