Name
MINUTE()
Synopsis
MINUTE(time
)
This function returns the minute value (0–59) of a given time. Here is an example:
SELECT CONCAT(HOUR(appointment), ':', MINUTE(appointment)) AS 'Appointment' FROM appointments WHERE client_id = '3992' AND appointment > CURDATE( ); +-------------+ | Appointment | +-------------+ | 13:30 | +-------------+
This statement is using the string function
CONCAT()
to paste together the hour and the
minute, with a colon as a separator. Of course, a function such as
DATE_FORMAT() would be a better choice for such a
task. If an invalid time is given (e.g., minutes or seconds in excess
of 59), NULL is returned and a warning issued:
SELECT MINUTE('13:60:00') AS 'Bad Time', MINUTE('13:30:00') AS 'Good Time'; +----------+-----------+ | Bad Time | Good Time | +----------+-----------+ | NULL | 30 | +----------+-----------+ 1 row in set, 1 warning (0.00 sec) SHOW WARNINGS; +---------+------+--------------------------------------------+ | Level | Code | Message | +---------+------+--------------------------------------------+ | Warning | 1292 | Truncated incorrect time value: '13:60:00' | +---------+------+--------------------------------------------+
Get MySQL in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.