Addition and Subtraction Functions
Perform arithmetic operations on numerical and date values.
The table below contains the supported unit for the following functions.
second
Seconds
minute
Minutes
hour
Hours
day
Days
week
Weeks
month
Months
quarter
Quarters
year
Years
DATE_ADD( [ <unit>, ] value, <date_expr> ) or DATEADD( [ <unit>, ] value, <date_expr> )
Returns a date expression after adding an interval value of type unit to the input date expression.
> select date_add('year', 5, cast('2000-08-05' as date));
2005-08-05DATE_DIFF( <date expr1>, <date_expr2> [, <unit> ] )
Returns the number of units between two date expressions.
unit - optional - The unit used to calculate the difference. Default value: day.
> select date_diff(cast('2006-01-12' as date), cast('2006-01-21' as date));
-9
> select date_diff(cast('2005-10-12' as date), cast('2005-03-12' as date), 'month');
7DATE_DIFF( [ <unit>, ] <date expr1>, <date_expr2> )
Returns the number of units between two date expressions.
unit - optional - The unit used to calculate the difference. Default value: day.
DATEDIFF( [ <unit> ] , <date expr1>, <date_expr2> )
Returns the number of units between two date expressions.
unit - optional - The unit used to calculate the difference. Default value: day.
TIMESTAMP_ADD( unit, value, <timestamp_expr> )
Returns a timestamp expression after adding an interval value of type unit to the input timestamp expr.
TIMESTAMP_DIFF( <timestamp_expr1>, <timestamp_expr2>, unit )
Returns the difference of timestamp expr1 and timestamp expr2 with respect to unit.
Date Time Operators
The following operators can be used to perform mathematical operations on date-time expressions.
+ - Addition Operator
- - Subtraction Operator
Combined Operators
Limits -
Week and quarter are not supported in interval (addition/subtraction )
Last updated
