w3resource

MySQL CURRENT_TIME() function

CURRENT_TIME() function

In MySQL, the CURRENT_TIME() returns the current time in ‘HH:MM:SS’ format or HHMMSS.uuuuuu format depending on whether numeric or string is used in the function. CURRENT_TIME() and CURRENT_TIME are the synonym of CURTIME(). It provides the current time without the date component.

Note: All of the example codes of this page will produce outputs depending upon the current time.

This function is useful in -

  • The primary purpose of the CURRENT_TIME() function is to provide a timestamp of the current time.
  • This is useful for filtering and querying data based on time intervals or time-based conditions.
  • When scheduling tasks, events, or alerts in applications, CURRENT_TIME() ensures that the system records the correct current time and updates accordingly.
  • In logging systems, CURRENT_TIME() is used to timestamp log entries, providing accurate information about when specific events occurred.
  • When troubleshooting, CURRENT_TIME() can assist in pinpointing the exact time when issues or errors occurred.
  • CURRENT_TIME() can be used to analyze trends and patterns in time-based data, such as user activity over different times of the day.
  • In performance analysis, CURRENT_TIME() helps track the duration of specific operations or processes.

Syntax:

CURRENT_TIME;

Syntax Diagram:

MySQL CURRENT_TIME() Function - Syntax Diagram

MySQL Version: 8.0


Pictorial Presentation:

Pictorial Presentation of MySQL CURRENT_TIME() function

Example-1: MySQL CURRENT_TIME

The following statement will return the current time in ‘HH:SS:MM’ format.

Code:

SELECT CURRENT_TIME;

Output:

mysql> SELECT CURRENT_TIME;
+--------------+
| CURRENT_TIME |
+--------------+
| 11:35:45     | 
+--------------+
1 row in set (0.00 sec)

Example-2:

The following statement will return the current time in ‘HH:SS:MM’ format.

Code:

SELECT CURRENT_TIME();

Output:

mysql> SELECT CURRENT_TIME();
+----------------+
| CURRENT_TIME() |
+----------------+
| 11:39:47       | 
+----------------+
1 row in set (0.01 sec)

Video Presentation:

All Date and Time Functions :

Click here to see the MySQL Date and time functions.

Previous: CURRENT_DATE()
Next: CURRENT_ TIMESTAMP()



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/mysql/date-and-time-functions/mysql-current_time-function.php