How to use the MySQL MINUTE() function

MySQL MINUTE() is a function that returns the minute part of a date or time value.

Posted on

MySQL MINUTE() is a function that returns the minute part of a date or time value. It can be used to extract the minute component from a datetime, date, or time expression. The function takes one argument: the date or time value. The return value is an integer from 0 to 59, representing the minute in the format ‘HH:MM:SS’ or HHMMSS.

Syntax

The syntax of the function is:

MINUTE(date_or_time)

The parameter is:

  • date_or_time: The date or time value to extract the minute from. It can be a datetime, date, or time expression, or a string in a valid date or time format.

Examples

Some examples of using the function are:

  • To get the minute part of the current time, use:

    SELECT MINUTE(CURTIME());
    

    The result is:

    20
    

    This means that the current time is 10:20:21.

  • To get the minute part of a datetime value, use:

    SELECT MINUTE('2023-11-15 16:45:12');
    

    The result is:

    45
    

    This means that the datetime value has 45 minutes.

  • To get the minute part of a time value, use:

    SELECT MINUTE('18:30:00');
    

    The result is:

    30
    

    This means that the time value has 30 minutes.

  • To get the minute part of a string in a valid date or time format, use:

    SELECT MINUTE('11/15/2023 4:45:12 PM');
    

    The result is:

    45
    

    This means that the string is converted to a datetime value and has 45 minutes.

  • To format a datetime value using the minute part, use:

    SELECT DATE_FORMAT('2023-11-15 16:45:12', '%H:%i');
    

    The result is:

    16:45
    

    This means that the datetime value is formatted as hour:minute, using the 24-hour clock.

Similar Functions

Some similar functions to MINUTE() are:

  • SECOND(): This function returns the second part of a date or time value, from 0 to 59.
  • HOUR(): This function returns the hour part of a date or time value, from 0 to 23.
  • MICROSECOND(): This function returns the microsecond part of a date or time value, from 0 to 999999.
  • EXTRACT(): This function extracts a specific part of a date or time value, such as year, month, day, hour, minute, second, or microsecond.