MySQL CURRENT TIME Function Examples

MySQL CURRENT TIME Function Examples

Here, you will learn how to use MySQL current time function with various examples. When you want to get the current time in MySQL queries that time you can use the easily uses the current time.

MySQL CURRENT_TIME() Function

The MySQL CURRENT_TIME function gets the current time. It is returned the value format as “HH-MM-SS” (string) or as HHMMSS.

In other words, the CURRENT_TIME function is used to return the current time.

Note:

This function is a synonym for CURTIME () that gets the current time, so you can choose which function you want to use.

Both functions return the current time as values ​​in HH: MM: SS ‘or HHMMSS format, depending on whether you want to the function is used in a string or numerical context.

Syntax

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

Let’s take the first example of current_time() function of MySQL is below:

SELECT CURRENT_TIME;

Output-1

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

Example-2

Now we take next example of current_time() with curtime() function, see the example below:

 SELECT 
 CURRENT_TIME,
 CURRENT_TIME(),
 CURTIME();

Result:

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

Example-3

Let’s take another example with the MySQL database. We will fetch employees’ data from database table employees who have start_time greater than the current time.

  SELECT * 
  FROM employees 
  WHERE  start_time > CURRENT_TIME()

Example-4

We take next example of current_time() using numeric context:

SELECT CURRENT_TIME + 0;

Output-4

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

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

Conclusion

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

You may like

  1. MySQL CURRENT TIMESTAMP Function Examples
  2. Get month name from date in mysql
  3. mysql get first day of the current month
  4. mysql last day of previous month
  5. Get month number from month name in mysql
  6. mysql get day of week number from date
  7. Mysql Get Data Of Current Date, Week, Month, YEAR
  8. Query For Get Data Of Last Day, Week, Month, YEAR – Mysql

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

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Javascript, JQuery, Laravel, Livewire, Codeigniter, Vue JS, Angular JS, React Js, WordPress, and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

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