MINUTE() Function Examples – MySQL

MINUTE() Function Examples – MySQL

MySQL tutorial – We are going to demonstrate to you how to use the Minute() function of MySQL with its syntax and examples.

In this MySQL tutorial, We will take database table related examples following 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.

You may like

  1. TIMESTAMP() Function Examples – MySQL
  2. TIMEDIFF() Function Examples – MySQL
  3. SEC_TO_TIME() Function Examples – MySQL
  4. QUARTER() Function Examples – MySQL
  5. STR_TO_DATE() Function Examples – MySQL
  6. PERIOD_DIFF() Function Examples – MySQL
  7. PERIOD_ADD() Function Examples – MySQL
  8. SECOND() Function Examples – MySQL
  9. MICROSECOND() Function Examples – MySQL
  10. MAKETIME() Function Examples – MySQL
  11. Localtime() Function Examples – MySQL
  12. CURTIME() Function Examples – MySQL
  13. MySQL CURRENT TIMESTAMP Function Examples
  14. MySQL CURRENT TIME Function Examples
  15. ADDTIME() Function Examples – MySQL
  16. HOUR() Function Examples – MySQL
  17. NOW() MySQL Function | MySQL
  18. MySQL DATE() And TIME() Functions (List)
  19. TIMESTAMPADD() Function Examples – MySQL
  20. TIMESTAMPDIFF() Function Examples – MySQL

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

Leave a Reply

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