SQL Keywords

SQL LOCALTIME

What is SQL LOCALTIME?

LOCALTIME returns the current local time (without time-zone offset) at the moment the statement starts.
Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Compatible dialects for SQL LOCALTIME: PostgreSQL, MySQL, MariaDB, Oracle, SQLite. Not available in SQL Server without workaround.

SQL LOCALTIME Full Explanation

LOCALTIME is a non-deterministic scalar function defined by the SQL standard. It yields the session’s local time as a TIME value that has no time-zone component. The value is constant for the duration of the statement in which it appears, making repeated references within one query return the same result.Precision handling- Standard SQL allows an optional fractional-seconds precision: LOCALTIME or LOCALTIME(p). The precision p is an integer from 0 to the implementation’s maximum (commonly 6), controlling the number of decimal places in the seconds field.Session time zone impact- Although the function name implies “local,” the actual return is the time adjusted to the database session’s time-zone setting. If the session offset changes (via SET TIME ZONE in PostgreSQL, for example), LOCALTIME immediately reflects the new offset in subsequent statements.Side-effect characteristics- LOCALTIME has no arguments, causes no side effects, and is classified as an immutable function for the lifetime of a single statement but volatile across statements.Relation to other functions- LOCALTIME is similar to CURRENT_TIME but excludes a time-zone displacement portion. It differs from LOCALTIMESTAMP, which returns both date and time. In MySQL, LOCALTIME is a synonym for NOW(), returning a DATETIME value that includes the date; therefore behavior varies by dialect.Caveats- Not all engines support fractional precision or the function name exactly as specified. SQL Server, for example, lacks LOCALTIME entirely; developers must use GETDATE() or CONVERT.- Because LOCALTIME lacks a date component, combining it with date arithmetic requires explicit casting or concatenation in some dialects.

SQL LOCALTIME Syntax

-- Standard SQL
LOCALTIME;
LOCALTIME(3);

SQL LOCALTIME Parameters

Example Queries Using SQL LOCALTIME

-- 1. Select current local time (default precision)
SELECT LOCALTIME AS current_time;

-- 2. Include milliseconds (precision 3)
SELECT LOCALTIME(3) AS current_time_ms;

-- 3. Log order creation time in a trigger (PostgreSQL)
INSERT INTO order_audit(order_id, action_time)
VALUES (NEW.id, LOCALTIME);

-- 4. Compare column against current time window
SELECT id
FROM tasks
WHERE reminder_time <= LOCALTIME(0)
  AND reminder_time >= LOCALTIME - INTERVAL '01:00' HOUR TO MINUTE;

Expected Output Using SQL LOCALTIME

  • Returns a single TIME value such as 14:23:11.
  • Returns a TIME value with milliseconds such as 14:23:11.145.
  • Inserts the current time into the action_time column for each new order.
  • Retrieves rows whose reminder_time falls within the last hour relative to execution time.

Use Cases with SQL LOCALTIME

  • Timestamping events where only time of day matters, date tracked elsewhere
  • Building time-based filters in dashboards without needing full timestamps
  • Auditing or logging within a trigger when storage columns are TIME-only
  • Quick debugging to see server session time zone settings

Common Mistakes with SQL LOCALTIME

  • Expecting LOCALTIME to return a date component – it does not in most engines except MySQL.
  • Assuming each call within a query returns a new time – value is fixed per statement.
  • Using LOCALTIME in SQL Server – function is unsupported; use GETDATE().
  • Forgetting to specify precision when sub-second accuracy is required.

Related Topics

CURRENT_TIME, LOCALTIMESTAMP, CURRENT_DATE, NOW(), SYSDATE, GETDATE()

First Introduced In

SQL-92 Standard

Frequently Asked Questions

What is the difference between LOCALTIME and CURRENT_TIME?

CURRENT_TIME returns a TIME WITH TIME ZONE in some systems, whereas LOCALTIME strips the time-zone offset and delivers a plain TIME value.

Can I specify precision with LOCALTIME?

Yes. Provide an integer in parentheses, such as LOCALTIME(3), to get milliseconds if the dialect supports it.

Why does LOCALTIME in MySQL include a date?

MySQL defines LOCALTIME as a synonym for NOW(), which returns a DATETIME value; therefore it includes the date by design.

How do I use LOCALTIME in SQL Server?

You cannot call LOCALTIME directly. Instead, use SELECT CAST(GETDATE() AS time); or the more precise SYSDATETIME() cast to TIME.

Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.
Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo

Check out other commonly used SQL Keywords!