MySQL ADDTIME() Function
MySQL ADDTIME(): Add Hours, Minutes, and Seconds to Time Values
The ADDTIME() function adds a time duration to a TIME or DATETIME expression and returns the shifted result. It handles standard clock times, elapsed durations beyond 24 hours, and negative offsets for subtracting time.
Scheduling systems rely on ADDTIME() to compute shift end times, delivery ETAs, and break durations.
Syntax
Pass a starting time or datetime along with the duration you want to add:
ADDTIME(base_expr, time_to_add)
base_expr: ATIMEorDATETIMEvalue (including fractional seconds up to 6 digits).time_to_add: ATIMEstring such as'02:30:00','-00:45:00', or'1 04:00:00'(1 day and 4 hours).
If base_expr is a TIME, ADDTIME() returns a TIME. If base_expr is a DATETIME, it returns a DATETIME.
Practical Example
Imagine your HR team tracks employee clock-in times in demo_employees and needs to calculate scheduled 8-hour-30-minute shift end timestamps.
SELECT
employee_id,
full_name,
shift_start,
ADDTIME(shift_start, '08:30:00') AS shift_end,
ADDTIME(shift_start, '-00:15:00') AS prep_window_start
FROM demo_employees
WHERE employee_id IN (11, 12, 13);
| employee_id | full_name | shift_start | shift_end | prep_window_start |
|---|---|---|---|---|
| 11 | Nadia Rahman | 2026-05-12 08:00:00 | 2026-05-12 16:30:00 | 2026-05-12 07:45:00 |
| 12 | Tariq Hasan | 2026-05-12 14:00:00 | 2026-05-12 22:30:00 | 2026-05-12 13:45:00 |
| 13 | Elena Novak | 2026-05-12 22:00:00 | 2026-05-13 06:30:00 | 2026-05-12 21:45:00 |
Notice how Elena's night shift crosses midnight cleanly, updating the calendar date to 2026-05-13.
Common Mistakes & NULL Behavior
Avoid these common pitfalls when working with ADDTIME():
- Passing a bare
DATEstring returnsNULL: CallingADDTIME('2026-05-12', '02:00:00')without a time portion fails to parse as aDATETIMEand returnsNULL. UseTIMESTAMP(order_date)or'2026-05-12 00:00:00'instead. NULLarguments produceNULL: Ifbase_exprortime_to_addisNULL,ADDTIME()immediately returnsNULL.- Invalid time strings fail: Values with minutes or seconds above
59, like'01:75:00', evaluate toNULL. TIMErange limits: PureTIMEresults are bounded between'-838:59:59'and'838:59:59'. Exceeding that range saturates the output or raises an error in strict mode.
Frequently Asked Questions
Can ADDTIME() add days as well as hours?
Yes. Prefix the time string with a day count and a space, such as ADDTIME('2026-05-12 09:00:00', '2 03:00:00'), which adds 2 days and 3 hours.
How do I subtract time using ADDTIME()?
Include a leading minus sign on the second argument, like ADDTIME('10:00:00', '-01:30:00'), which returns '08:30:00'.
Does ADDTIME() support microseconds?
Yes. Both arguments accept up to six decimal places, such as '00:00:01.250000', and the return value keeps the higher precision.
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Try it Yourself
Experiment with the code from this lesson in our interactive playground.