MariaDB ADDTIME() Function
In MariaDB, ADDTIME() is a built-in function that adds a specified time interval to a specified time and returns the result.
MariaDB ADDTIME() Syntax
This is the syntax of the MariaDB ADDTIME() function:
ADDTIME(timeExpr1, timeExpr2)
Parameters
timeExpr1-
Required. It is a datetime or time expression.
timeExpr2-
Required. It is a time expression. It can be positive or negative.
If you provide no parameters or the wrong number of parameters, MariaDB will report an error: ERROR 1582 (42000): Incorrect parameter count in the call to native function 'ADDTIME'.
Return value
The MariaDB ADDTIME() function adds timeExpr2 to timeExpr1 and returns the result.
The ADDTIME() function determines the type of the return value according to the following rules:
- If the
timeExpr1parameter is of dynamic type, theADDTIME()function returns a value ofTIMEtype. - Otherwise, the data type returned by the
ADDTIME()function is the same as the first parameter.
MariaDB ADDTIME() Examples
Example 1
Add 10 seconds to the specified time:
SELECT
ADDTIME('2020-10-10 10:10:10', 10),
ADDTIME('10:10:10', 10)\G
Output:
ADDTIME('2020-10-10 10:10:10', 10): 2020-10-10 10:10:20
ADDTIME('10:10:10', 10): 10:10:20Example 2
Add 1 minute to the specified time:
SELECT
ADDTIME('10:10:10', 100),
ADDTIME('10:10:10', '100'),
ADDTIME('10:10:10', '0:01:00')\G
Output:
ADDTIME('10:10:10', 100): 10:11:10
ADDTIME('10:10:10', '100'): 10:11:10
ADDTIME('10:10:10', '0:01:00'): 10:11:10Example 3
Adds and subtracts 1 hour, 10 minutes, 10 seconds, and 10 microseconds to the specified time.
SELECT
ADDTIME('10:00:00', '01:10:10.000010'),
ADDTIME('10:00:00', '-01:10:10.000010'),
SUBTIME('10:00:00', '01:10:10.000010')\G
Output:
ADDTIME('10:00:00', '01:10:10.000010'): 11:10:10.000010
ADDTIME('10:00:00', '-01:10:10.000010'): 08:49:49.999990
SUBTIME('10:00:00', '01:10:10.000010'): 08:49:49.999990Here, the minus sign before '-01:10:10.000010' means to subtract '01:10:10.000010' from '10:00:00', which is the same as the SUBTIME() function.
Conclusion
In MariaDB, ADDTIME() is a built-in function that adds a specified time interval to a specified time and returns the result.