MySQL ADDTIME() Function

The ADDTIME() function in MySQL lets you add a time interval to an existing time or datetime value. This is incredibly useful for tasks like calculating future dates or times, or adjusting timestamps.



ADDTIME(): Definition and Usage

ADDTIME() takes a time or datetime value and a time interval as input. It returns a new time or datetime value that reflects the addition of the interval to the original value. You can add or subtract time by using positive or negative intervals.

Syntax

Syntax

ADDTIME(datetime, addtime)
      

Parameter Values

Parameter Description
datetime The original time or datetime value. This is required.
addtime The time interval to add (or subtract if negative). This can be expressed in various formats (seconds, hours:minutes:seconds, days hours:minutes:seconds, etc.). This is required.

Examples

Adding Seconds to a Datetime

Add 2 seconds to a datetime value.

Syntax

SELECT ADDTIME("2017-06-15 09:34:21", "2");
      
Output

2017-06-15 09:34:23
      

Adding More Complex Intervals

Adding various time units (seconds, microseconds).

Syntax

SELECT ADDTIME("2017-06-15 09:34:21.000001", "5.000003");
      
Output

2017-06-15 09:34:26.000004
      

Adding Days, Hours, Minutes, Seconds, and Microseconds

Syntax

SELECT ADDTIME("2017-06-15 09:34:21.000001", "5 2:10:5.000003");
      
Output

2017-06-20 11:44:26.000004
      

Adding to a Time Value (only time portion)

Syntax

SELECT ADDTIME("09:34:21.000001", "2:10:5.000003");
      
Output

11:44:26.000004