MySQL MINUTE() Function Example

MySQL MINUTE() Function; In this tutorial, We are going to demonstrate to you how to use the Minute() function of MySQL with its syntax and examples.

In this tutorial, we will take some examples using minute function; as shown below:

  • Find the last month’s records from the database table who has login greater than 10 minutes.
  • Delete all rows older than 10 minutes.
  • Find the current month records who have login greater than 8 minutes.
  • How to select all records that are 10 minutes within the current timestamp in MySQL?

MySQL Minute() Function

In MySQL, The Minute() function is used to get the minute from the given DateTime.

Note: The MINUTE function returns the minute (a number from 0 to 59) given a date value.

Syntax

The syntax for the MINUTE function is:

MINUTE( datetimevalue )

Let’s see examples of some MINUTE functions and demonstrate how to use the MINUTE function.

Example-1

Let’s take the first example of a MINUTE() function. It will return the minute from a given date/time.

SELECT MINUTE('11:40:30');

Output-1

+-------------------+
|MINUTE('11:40:30') |
+-------------------+
|               40  |
+------------------ +

Example-2

Let’s take another example with MySQL NOW() function. It will return the current hour minute, see the below example:

SELECT MINUTE(NOW());

Output-2

+--------------------+
| MINUTE(NOW)        |
+--------------------+
|                37  |
+--------------------+ 

Example-3

We take an example with CURTIME() function of MySQL with MINUTE would display the minute portion of the current system time:

SELECT MINUTE(CURTIME());

Output-3

+--------------------+
| MINUTE(CURTIME())  |
+--------------------+
|                37  |
+--------------------+ 

Example-4

Let’s take a new example with database table employees. We will fetch users who have login time greater than 10 minutes. So below the given MySQL query is used to getting the last month records from the database table who has login greater than 10 minutes:

 ====================================For Current Month=============================
 SELECT name, created_at as created_date
 FROM employees
 WHERE MINUTE(login_time) > 10 AND
 MONTH(created_at) = MONTH(NOW()) - 1 ORDER BY `id` DESC ;

====================================For Current Month=============================

 SELECT name, created_at as created_date
 FROM employees
 WHERE MINUTE(login_time) > 8 AND
 MONTH(created_at) = MONTH(NOW()) ORDER BY `id` DESC ; 

Example-5

In MySQL – Delete all rows older than 10 minutes. Use the below query for that:

if time_created is mysql timestamp, you can use the query for delete.

DELETE
FROM employees
WHERE time_created < (NOW() - INTERVAL 10 MINUTE)

Example-6

How to select all records that are 10 minutes within the current timestamp in MySQL?

You can use the below query to select all records that are 10 minutes within the current timestamp in MySQL.

 SELECT *
 FROM employees
 WHERE  date_time >= NOW() - INTERVAL 10 MINUTE

Conclusion

Here, you have learned how to use MySQL Minute() function with examples.

Recommended MySQL Tutorials

If you have any questions or thoughts to share, use the comment form below to reach us.

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *