Mysql Addtime Function

MySQL: ADDTIME Function

This tutorial explains how to use the MySQL ADDTIME function with syntax and examples.

Description

The MySQL ADDTIME function returns a time/datetime value after which a certain time interval has been added.

Syntax

The syntax for the ADDTIME function in MySQL is:

ADDTIME( start_value, time )

Parameters or Arguments

start_value

The time or datetime value to which the time interval should be added.

time

The value of the time interval that you wish to add. It can be a positive or negative value.

Note

Applies To

The ADDTIME function can be used in the following versions of MySQL:

  • MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1.1

Example

Let's look at some MySQL ADDTIME function examples and explore how to use the ADDTIME function in MySQL.

For example:

mysql> SELECT ADDTIME('2014-02-13 08:44:21.000001', '2.000001');
Output: '2014-02-13 08:44:23.000002'

mysql> SELECT ADDTIME('2014-02-13 08:44:21.000001', '3:2.000001');
Output: '2014-02-13 11:46:21.000002'

mysql> SELECT ADDTIME('2014-02-13 08:44:21.000001', '4:3:2.000001');
Output: '2014-02-13 12:47:23.000002'

mysql> SELECT ADDTIME('2014-02-13 08:44:21.000001', '5 4:3:2.000001');
Output: '2014-02-18 12:47:23.000002'

mysql> SELECT ADDTIME('01:15:23.999998', '0.000001');
Output: '01:15:23.999999'

mysql> SELECT ADDTIME('01:15:23.999998', '5.000001');
Output: '01:15:28.999999'

mysql> SELECT ADDTIME('01:15:23.000001', '8:12:15.003441');
Output: '09:27:38.003442'

mysql> SELECT ADDTIME('01:15:23.000001', '-8:12:15.003441');
Output: '-06:56:52.003440'