w3resource

MySQL MINUTE() function

MINUTE() function

MySQL MINUTE() returns a MINUTE from a time or datetime value.

Syntax:

MINUTE(time1);

Where time1 is time.

Syntax Diagram:

MySQL MINUTE() Function - Syntax Diagram

MySQL Version: 5.6


Video Presentation

Pictorial Presentation

Pictorial Presentation of MySQL MINUTE() function

Example: MySQL MINUTE() function

The above statement will return MINUTEs from the given datetime 2009-05-18 10:15:21.000423.

Code

SELECT MINUTE('2009-05-18 10:15:21.000423');

Sample Output:

mysql> SELECT MINUTE('2009-05-18 10:15:21.000423');
+--------------------------------------+
| MINUTE('2009-05-18 10:15:21.000423') |
+--------------------------------------+
|                                   15 | 
+--------------------------------------+
1 row in set (0.01 sec)

PHP script

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>example-MINUTE-function - php mysql examples | w3resource</title>
<meta name="description" content="example-MINUTE-function - php mysql examples | w3resource">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<h2>Extract MINUTE from 2009-05-18 10:15:21.000423:</h2>
<table class='table table-bordered'>
<tr>
<th>MINUTE from 2009-05-18 10:15:21.000423</th>
</tr>
<?php
$hostname="your_hostname";
$username="your_username";
$password="your_password";
$db = "your_dbname";
$dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password);
foreach($dbh->query('SELECT MINUTE("2009-05-18 10:15:21.000423")') as $row) {
echo "<tr>";
echo "<td>" . $row['MINUTE("2009-05-18 10:15:21.000423")'] . "</td>"; 
echo "</tr>";
}
?>
</tbody></table>
</div>
</div>
</div>
</body>
</html>

View the example in browser

JSP script

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>example-from_days-function</title>
</head>
<body>
<%
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
String Host = "jdbc:mysql://localhost:3306/w3resour_bookinfo";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
connection = DriverManager.getConnection(Host, "root", "datasoft123");
statement = connection.createStatement();
String Data ="SELECT MINUTE('2009-05-18 10:15:21.000423')";
rs = statement.executeQuery(Data);
%>
<TABLE border="1">
<tr width="10" bgcolor="#9979">
<td>MINUTE from 2009-05-18 10:15:21.000423</td>
</tr>
<%
while (rs.next()) {
%>
<TR>
<TD><%=rs.getString("MINUTE('2009-05-18 10:15:21.000423')")%></TD>
</TR>
<%   }    %>
</table>
<%
rs.close();
statement.close();
connection.close();
} catch (Exception ex) {
out.println("Can’t connect to database.");
}
%>
</body>
</html>

Example : MINUTE() function with current date

The following statement will return MINUTEs from the current time which is coming from the CURRENT_TIME(). The first column in the output shows the current time (for reference).

Code:

SELECT CURRENT_TIME(),MINUTE(CURRENT_TIME());

Note: Since CURRENT_TIME() is used, your output may vary from the output shown.

Sample Output:

mysql> SELECT CURRENT_TIME(),MINUTE(CURRENT_TIME());
+----------------+------------------------+
| CURRENT_TIME() | MINUTE(CURRENT_TIME()) |
+----------------+------------------------+
| 18:04:03       |                      4 | 
+----------------+------------------------+
1 row in set (0.00 sec)

PHP script

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>example1-MINUTE-function - php mysql examples | w3resource</title>
<meta name="description" content="example1-MINUTE-function - php mysql examples | w3resource">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<h2>Current time and MINUTE part of current time:</h2>
<table class='table table-bordered'>
<tr>
<th>Current time</th><th>MINUTE part of Current time</th>
</tr>
<?php
$hostname="your_hostname";
$username="your_username";
$password="your_password";
$db = "your_dbname";
$dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password);
foreach($dbh->query('SELECT CURRENT_TIME(),MINUTE(CURRENT_TIME())') as $row) {
echo "<tr>";
echo "<td>" . $row['CURRENT_TIME()'] . "</td>";
echo "<td>" . $row['MINUTE(CURRENT_TIME())'] . "</td>";
echo "</tr>";
}
?>
</tbody></table>
</div>
</div>
</div>
</body>
</html>

View the example in browser

All Date and Time Functions:

Click here to see the MySQL Date and time functions.

Previous: MICROSECOND()
Next: MONTH()