Date Manipulation - Date Arithmetic


Let us understand how to perform arithmetic on dates or timestamps.

  • date_add can be used to add or subtract days.
  • days_sub can be used to subtract or add days.
  • datediff can be used to get difference between 2 dates
  • add_months can be used add months to a date
SELECT date_add(current_date, 32);
SELECT date_add('2018-04-15', 730);
SELECT date_add('2018-04-15', -730);

SELECT date_sub(current_date, 30);

SELECT datediff('2019-03-30', '2017-12-31');

SELECT add_months(current_date, 3);
SELECT add_months('2019-01-31', 1);
SELECT add_months('2019-05-31', 1);
SELECT add_months(current_timestamp, 3);

SELECT date_add(current_timestamp, -730);

Practice hive on state of the art Big Data cluster -
You can sign up for our courses on Udemy using $10 coupons - Udemy Coupons - Big Data Courses