MySQL ADDTIME() Function

In MySQL, the ADDTIME() function adds a specified time value to another specified time and returns the result.

ADDTIME() Syntax

Here is the syntax of MySQL 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.

Return value

The 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 timeExpr1 parameter is a dynamic type, the function returns a TIME value.
  • Otherwise, the function returns the same data type as the first argumenttimeExpr1.

ADDTIME() Examples

Here are some examples of the ADDTIME() function.

Example 1

Add 10 seconds to the specified time:

SELECT
    ADDTIME('2020-10-10 10:10:10', 10),
    ADDTIME('10:10:10', 10)\G
ADDTIME('2020-10-10 10:10:10', 10): 2020-10-10 10:10:20
           ADDTIME('10:10:10', 10): 10:10:20

Example 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
      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:10

Example 3

Adds or 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
 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.999990

Here, the minus sign in front of '-01:10:10.000010' means subtract '01:10:10.000010' from '10:00:00', which is the same as the SUBTIME() function with parameter '01:10:10.000010'.