Lesson

MySQL MAKETIME() Function

10 min reading
Free Course

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 than 23, within MySQL's -838 to 838 TIME range).
  • minute: Integer strictly between 0 and 59.
  • second: Integer or decimal value strictly >= 0 and < 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: minute must be 0..59 and second must be 0 to < 60. Calling MAKETIME(10, 60, 0), MAKETIME(10, -5, 0), or MAKETIME(10, 0, 60) returns NULL instead of rolling into the next hour or minute!
  • NULL arguments produce NULL: If any of hour, minute, or second is NULL, MAKETIME() returns NULL.
  • Hour clamping at 838 / -838: Because MySQL TIME caps at '-838:59:59' and '838:59:59', passing MAKETIME(900, 0, 0) clamps to '838:59:59' (or raises an error in strict mode).
  • Negative durations use negative hour only: Write MAKETIME(-2, 30, 0) to produce '-02:30:00'. Passing negative minutes or seconds returns NULL.

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'.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Try it Yourself

Experiment with the code from this lesson in our interactive playground.

Open Playground
MySQL Topic Hub

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum