AppDividend
Latest Code Tutorials

SQL CURRENT_TIME Function Example

0

SQL CURRENT_TIME function is used for returning the current time of the database server. The time will be returned either as “HH-MM-SS” (string) or as HHMMSS.uuuuuu (numeric).

SQL CURRENT_TIME Function

The CURRENT_TIME() function returns the current time in the database.

The CURRENT_TIME is a standard-SQL function supported by almost all database systems such as DB2, Firebird, MySQL, PostgreSQL, and SQLite.

SQL Server does not support the CURRENT_TIME function; however, you can use the GET_DATE() function to return the current time.

See the following syntax.

Syntax

SELECT CURRENT_TIME();

See the following example.

Example

SELECT CURRENT_TIME();

Output

22:22:23

Query 2

SELECT CURRENT_TIME () +1

Output

222223

Explanation

Adding 1 to this function, it returned the value in numeric form.

NOTE:

Above CURRENT_TIME function applies only to MYSQL.

To use it on the SQL_SERVER getdate () function has to be used.

Syntax

SELECT CONVERT (TIME, GETDATE ()) AS 'CURRENT_TIME using GETDATE()';

Output

CURRENT_TIME using GETDATE()
22:43:56.2500000

 

Oracle does not have a specific function to return the current time. However, you can use the SYSDATE function that returns both date and time and uses the TO_CHAR() function to format the time.

See the following query.

SELECT 
    TO_CHAR(SYSDATE, 'HH24:MI:SS') 
FROM 
    dual;

Output

17:46:28

In this tutorial, you have learned how to use the SQL CURRENT_TIME function to get the current time of the database server.

The return value does not change during the transaction. Thus, multiple calls to CURRENT_TIME() within the same transaction return the same timestamp.

MySQL 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 synonyms of CURTIME().

Conclusion

If you want to get the current time from the database server, then you can use the CURRENT_TIME() function.

Finally, SQL CURRENT_TIME Function Example is over.

Related Posts

SQL GETUTCDATE Function

SQL GETDATE Function

SQL SYSDATETIME Function

SQL Format Function

SQL Date Functions

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.