MySQL CURRENT_TIME() Function

MySQL CURRENT TIME function; Through this tutorial, i am going to show you MySQL current time function with help of examples.

MySQL CURRENT_TIME() Function

CURRENT_TIME() function in MySQL is used to check the current time. It returns the current time as a value in ‘hh:mm:ss’ or hhmmss format, depending on whether the function is used in string or numeric context

Syntax of MySQL CURRENT_TIME() Function

The CURRENT_TIME() function syntax is:

CURRENT_TIME
=================OR================
CURRENT_TIME([optional])

The (optional)  an argument can be used to provide the fractional seconds precision. If provided, the return value will include fractional seconds up to the number provided. You can specify a optionalvalue between 0 and 6.

Example 1 – MySQL CURRENT_TIME() Function

Let’s take the first example of current_time() function of MySQL; as follows:

SELECT CURRENT_TIME;

Output-1

+--------------+
| CURRENT_TIME |
+--------------+
| 11:02:42     |
+--------------+

Example 2 – MySQL CURRENT_TIME() Function

Let’s take an example using current_time() with curtime() function; as follows:

 SELECT 
 CURRENT_TIME,
 CURRENT_TIME(),
 CURTIME();

Output-2

+--------------+----------------+-----------+
| CURRENT_TIME | CURRENT_TIME() | CURTIME() |
+--------------+----------------+-----------+
| 11:05:06     | 11:05:06       | 11:05:06  |
+--------------+----------------+-----------+

Example 3 – Fetch Data Using CURRENT_TIME() Function

To fetch users’ data from database table users who have start_time greater than the current time; as follows:

  SELECT * 
  FROM employees 
  WHERE  start_time > CURRENT_TIME()

Example 4 – Add Time to MySQL CURRENT_TIME() Function

Let’s take an example using the MySQL current_time() using numeric context; as follows:

SELECT CURRENT_TIME + 0;

Output-4

+------------------+
| CURRENT_TIME + 0 |
+------------------+
|           100425 |
+------------------+

In the above example, we have added zero to the time.

Conclusion

MySQL CURRENT_TIME() Function tutorial, you have learned how to use MySQL CURRENT_TIME() function with various examples.

Leave a Comment