MySQL MAKETIME() Function
The MAKETIME()
function in MySQL constructs a time value from its individual components: hours, minutes, and seconds. This is very useful for creating time values programmatically, particularly when you're working with time data that's stored or calculated as separate hour, minute, and second values.
MAKETIME(): Definition and Usage
MAKETIME()
offers a convenient way to build a time value instead of manually constructing a time string. It takes three integer arguments representing the hours, minutes, and seconds. The output is a time value in 'HH:MM:SS' format.
Syntax
Syntax
MAKETIME(hour, minute, second)
Parameter Values
Parameter | Description |
---|---|
hour |
The hour value (0-23). This is required. |
minute |
The minute value (0-59). This is required. |
second |
The seconds value (0-59). This is required. |
Examples
Creating a Time Value
This example creates the time 11:35:04.
Syntax
SELECT MAKETIME(11, 35, 4);
Output
11:35:04
Creating Different Time Values
These examples show how to create various time values using MAKETIME()
.
Syntax
SELECT MAKETIME(16, 1, 0); -- 16:01:00
SELECT MAKETIME(21, 59, 59); -- 21:59:59
SELECT MAKETIME(838, 59, 59); -- 11:19:59 (Hours over 23 are handled by modulo arithmetic)
Output
16:01:00
21:59:59
11:19:59