MySQL MAKETIME() Function
MySQL MAKETIME(): Build a Time Value From Hour, Minute, and Second
The MAKETIME() function constructs a TIME value from three numeric arguments: hour, minute, and second. Unlike clock functions limited to 24 hours, MAKETIME() supports negative hours and elapsed durations up to 838 hours.
Time-tracking apps use MAKETIME() to assemble clean TIME values from separate integer columns or computed schedule parts.
Syntax
Supply hour, minute, and second values in order:
MAKETIME(hour, minute, second)
hour: Integer (can be negative or greater than23, within MySQL's-838to838TIMErange).minute: Integer strictly between0and59.second: Integer or decimal value strictly>= 0and< 60(supports fractional seconds).
Practical Example
Suppose demo_employees stores shift start hours and minutes in separate columns, and you assemble a valid TIME value for reporting.
SELECT
employee_id,
full_name,
MAKETIME(9, 30, 0) AS standard_start,
MAKETIME(14, 15, 30.50) AS afternoon_cutoff,
MAKETIME(40, 0, 0) AS weekly_hours_target
FROM demo_employees
WHERE employee_id = 11;
| employee_id | full_name | standard_start | afternoon_cutoff | weekly_hours_target |
|---|---|---|---|---|
| 11 | Nadia Rahman | 09:30:00 | 14:15:30.50 | 40:00:00 |
Notice how MAKETIME(40, 0, 0) cleanly represents a 40-hour duration (40:00:00), and 30.50 preserves fractional seconds.
Common Mistakes & NULL Behavior
Watch out for these strict rules when using MAKETIME():
- Out-of-range minutes or seconds return
NULL:minutemust be0..59andsecondmust be0to< 60. CallingMAKETIME(10, 60, 0),MAKETIME(10, -5, 0), orMAKETIME(10, 0, 60)returnsNULLinstead of rolling into the next hour or minute! NULLarguments produceNULL: If any ofhour,minute, orsecondisNULL,MAKETIME()returnsNULL.- Hour clamping at
838/-838: Because MySQLTIMEcaps at'-838:59:59'and'838:59:59', passingMAKETIME(900, 0, 0)clamps to'838:59:59'(or raises an error in strict mode). - Negative durations use negative
houronly: WriteMAKETIME(-2, 30, 0)to produce'-02:30:00'. Passing negative minutes or seconds returnsNULL.
Frequently Asked Questions
Why did MAKETIME(8, 75, 0) return NULL instead of 09:15:00?
MAKETIME() validates minute (0..59) and second (0..59.999999) strictly and does not carry overflow into hour. Use SEC_TO_TIME() if you need automatic overflow conversion.
Can MAKETIME() accept decimal seconds?
Yes. Passing MAKETIME(12, 0, 45.125) returns '12:00:45.125' with fractional seconds preserved.
How do I combine MAKEDATE() and MAKETIME() into a DATETIME?
Pass both into TIMESTAMP(MAKEDATE(2026, 132), MAKETIME(14, 30, 0)) to produce '2026-05-12 14:30:00'.
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.