Summary: in this tutorial, you will learn how to use the SQL CURRENT_TIME
function to get the current time.
To get the current time of the database server, you use the CURRENT_TIME
function. The following illustrates the syntax:
CURRENT_TIME
Code language: SQL (Structured Query Language) (sql)
The following statement returns the current time:
SELECT CURRENT_TIME;
Code language: SQL (Structured Query Language) (sql)
Here is the output:
10:23:29
Code language: SQL (Structured Query Language) (sql)
The CURRENT_TIME
is a standard-SQL function supported by the 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 as shown in the following query:
SELECT CONVERT(TIME, GETDATE())
AS 'CURRENT_TIME using GETDATE()'
Code language: SQL (Structured Query Language) (sql)
The following shows the output:
CURRENT_TIME using GETDATE()
----------------------------
17:46:28.2500000
Code language: SQL (Structured Query Language) (sql)
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:
SELECT
TO_CHAR(SYSDATE, 'HH24:MI:SS')
FROM
dual;
Code language: SQL (Structured Query Language) (sql)
The output is:
17:46:28
Code language: SQL (Structured Query Language) (sql)
In this tutorial, you have learned how to use the SQL CURRENT_TIME
function to get the current time of the database server.