LOCALTIME

LOCALTIME is a SQL function used to retrieve the current date and time on the system. The result is displayed based on the local time zone of the system where the database is running.

LOCALTIME [( precision )]

  • precision: This parameter specifies the number of fractional digits retained in the seconds field. The input can be an integer ranging between 0 and 6. If no precision parameter is provided, PostgreSQL will default to 0, meaning no fractional second digits are shown.

Example

SELECT LOCALTIME;

Output

15:26:43.449135

Explanation

The SQL command SELECT LOCALTIME; is asking the database to return the current time where the server is located.

LOCALTIME()

Example

SELECT LOCALTIME AS CurrentTime;

Output

CurrentTime
--------------------
12:24:35

Explanation

In the example, the SQL command LOCALTIME returns the current time from the system’s time zone. The result is displayed in ‘HH:MM:SS’ format.

LOCALTIME()

Example

SELECT LOCALTIME FROM dual;

Output

10:30:15.123456

Explanation

The LOCALTIME function is used to return the current date and time in the time zone of the current SQL session as set by the database. This was demonstrated in the example code with a fetch from the pseudo-table “dual”. The output is an example timestamp of the moment the function was called.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.