MySQL ADDTIME() function; In this tutorial, i am going to show you MySQL addtime() function with the help of examples.
MySQL ADDTIME() Function
ADDTIME() function in MySQL is used to add the specified time intervals to the given date and time
Syntax of MySQL ADDTIME() Function
The addtime() function basic syntax is:
ADDTIME(first,second)
The addtime() function required two parameters. First, param is the original date/time value, and the second param is the amount of time you want to add to it.
Example 1 – MySQL ADDTIME() Function
Let’s take the first example of addtime() :
SELECT ADDTIME('01:00:00', '03:40:00') AS Result;
Output-1
+----------+ | Result | +----------+ | 04:40:00 | +----------+
So the first param is increased by the amount of the second param.
Example 2 – MySQL ADDTIME() with Now() Function
Let’s take an second example using the MySQL addtime() with NOW(); as follows:
SELECT ADDTIME(now(), '02:00:00') AS result
Output-2
+----------+ | Result | +----------+ | 12:40:00 | +----------+
Using addtime(), we have added 2 hours in the current time.
Example 3 – MySQL ADDTIME() with Fractional Seconds
The time value can have a fractional seconds part if required:
SELECT ADDTIME('01:00:00.000000', '03:40:00.123456') AS Result;
Output-3
+-----------------+ | Result | +-----------------+ | 04:40:00.123456 | +-----------------+
So, in this case, we increased the day component as well as the time component.
Example 4 – MySQL ADDTIME() with Query
To add 5 hours in current time and fetch employees data from database table employees using addtime() function; as follows:
SELECT * FROM employees WHERE start_time > ADDTIME(now(), '05:00:00')
Conclusion
MySQL ADDTIME() Function tutorial, you have learned how to use MySQL ADDTIME() function with various examples.