All Products
Search
Document Center

Lindorm:Time functions

Last Updated:Mar 28, 2026

LindormTable supports four time functions for formatting timestamps, converting between UNIX timestamps and session-local timestamps, and calculating date differences. These functions are applicable only to LindormTable. All functions run in the time zone of the current session.

Prerequisites

Before you begin, ensure that you have:

  • LindormTable 2.7.8 or later (for DATE_FORMAT, FROM_UNIXTIME, and DATEDIFF)

  • Lindorm SQL 2.8.7.0 or later (for DATE_FORMAT, FROM_UNIXTIME, and DATEDIFF)

  • LindormTable 2.8.0 or later and Lindorm SQL 2.9.0.0 or later (for UNIX_TIMESTAMP)

To view or upgrade the LindormTable minor engine version, see Release notes of LindormTable and Upgrade the minor engine version of a Lindorm instance. To view the Lindorm SQL version, see SQL versions.

Supported functions

FunctionDescription
DATE_FORMATFormats a timestamp using the time zone of the current session.
FROM_UNIXTIMEConverts a Number-type value (BIGINT, INTEGER, SMALLINT, or TINYINT) to a timestamp using the time zone of the current session. The inverse of UNIX_TIMESTAMP.
DATEDIFFReturns the difference in days between two timestamps, based on date values only.
UNIX_TIMESTAMPConverts a timestamp or timestamp string to a UNIX timestamp. Returns a DOUBLE value in seconds. The inverse of FROM_UNIXTIME.

DATE_FORMAT

Formats a timestamp using the time zone of the current session. To view or set the session time zone, see Specify a time zone for a LindormTable connection.

Syntax

DATE_FORMAT(TIMESTAMP ts, STRING format)

Parameters

ParameterRequiredDescription
tsYesThe timestamp to format.
formatYesA format string composed of format specifiers (for example, %Y-%m-%d). Characters not starting with % are returned as-is. For the full list of supported specifiers, see Format specifiers.

Example

Format the timestamp 2024-01-01 17:20:35 as at 17:20:35 on Jan 1st, 2024:

SELECT DATE_FORMAT('2024-01-01 17:20:35', 'at %T on %b %D, %Y');

Output:

+------------------------------+
| EXPR$0                       |
+------------------------------+
| at 17:20:35 on JAN 1st, 2024 |
+------------------------------+

FROM_UNIXTIME

Converts a Number-type value to a timestamp using the time zone of the current session. This is the inverse of UNIX_TIMESTAMP. Accepts BIGINT, INTEGER, SMALLINT, and TINYINT values. The input represents seconds elapsed since 1970-01-01 00:00:00 UTC, with up to three decimal places retained.

Only the MySQL protocol supports changing the time zone of a connection. See Use the MySQL protocol to develop applications (recommended) and Use a MySQL client to connect to and use LindormTable.

Syntax

-- Convert a UNIX timestamp to a session-local timestamp.
FROM_UNIXTIME(Number seconds)

-- Convert and format the result.
-- Equivalent to: DATE_FORMAT(FROM_UNIXTIME(seconds), format)
FROM_UNIXTIME(Number seconds, STRING format)

The two-parameter form is equivalent to calling DATE_FORMAT on the result of the one-parameter form. The format parameter accepts the same specifiers as DATE_FORMAT. For details, see Format specifiers.

Parameters

ParameterRequiredDescription
secondsYesA UNIX timestamp in seconds. Up to three decimal places are retained. The value represents seconds elapsed since 1970-01-01 00:00:00 UTC.
formatNoA format string. Uses the same specifiers as DATE_FORMAT.

Examples

Example 1: Convert a UNIX timestamp

Convert 10.1578 to a timestamp using the time zone of the current session:

SELECT FROM_UNIXTIME(10.1578);

Output:

+-------------------------+
| EXPR$0                  |
+-------------------------+
| 1970-01-01 08:00:10.158 |
+-------------------------+

Change the session time zone to +03:00 and convert again:

-- Change the session time zone.
SET @@time_zone='+03:00';

-- Convert using the new time zone.
SELECT FROM_UNIXTIME(10.1578);

Output:

+-------------------------+
| EXPR$0                  |
+-------------------------+
| 1970-01-01 03:00:10.158 |
+-------------------------+

Example 2: Convert and format

Convert 10.1578 and format the result using the time zone of the current session:

SELECT FROM_UNIXTIME(10.1578, 'at %T on %b %D, %Y');

Output:

+------------------------------+
| EXPR$0                       |
+------------------------------+
| at 08:00:10 on JAN 1st, 1970 |
+------------------------------+

Change the session time zone to +03:00 and format again:

-- Change the session time zone.
SET @@time_zone='+03:00';

-- Convert and format using the new time zone.
SELECT FROM_UNIXTIME(10.1578, 'at %T on %b %D, %Y');

Output:

+------------------------------+
| EXPR$0                       |
+------------------------------+
| at 03:00:10 on JAN 1st, 1970 |
+------------------------------+

DATEDIFF

Returns the difference in days between two timestamps in the time zone of the current session. The result equals ts1 - ts2, comparing date values only — hours, minutes, and seconds are ignored.

  • Positive result: ts1 is a later date than ts2.

  • Negative result: ts1 is an earlier date than ts2.

  • Zero: ts1 and ts2 fall on the same date.

Syntax

DATEDIFF(TIMESTAMP ts1, TIMESTAMP ts2)

Parameters

ParameterRequiredDescription
ts1YesThe first timestamp.
ts2YesThe second timestamp.

Examples

Example 1: ts1 is earlier than ts2

SELECT DATEDIFF('2024-01-01 15:30:00', '2024-01-02 00:59:59');

Output:

+--------+
| EXPR$0 |
+--------+
|     -1 |
+--------+

Example 2: ts1 is later than ts2

SELECT DATEDIFF('2024-01-05 15:30:00', '2024-01-02 00:59:59');

Output:

+--------+
| EXPR$0 |
+--------+
|      3 |
+--------+

Example 3: ts1 and ts2 fall on the same date

Time-of-day values differ, but the date is the same, so the result is 0:

SELECT DATEDIFF('2024-01-02 15:30:00', '2024-01-02 00:59:59');

Output:

+--------+
| EXPR$0 |
+--------+
|      0 |
+--------+

UNIX_TIMESTAMP

Converts a timestamp or timestamp string to a UNIX timestamp. Returns a DOUBLE value. This is the inverse of FROM_UNIXTIME.

Important

UNIX_TIMESTAMP requires LindormTable 2.8.0 or later and Lindorm SQL 2.9.0.0 or later. Upgrade the LindormTable minor engine version in the Lindorm console if needed.

The precision of the returned value depends on the input type:

  • TIMESTAMP input: 3 decimal places retained.

  • VARCHAR input: The timestamp string represents the timestamp in the time zone of the current session. Up to 6 decimal places are retained.

UNIX_TIMESTAMP can be used in:

Syntax

UNIX_TIMESTAMP(ts)

Parameters

ParameterRequiredDescription
tsYesThe timestamp to convert. Must be TIMESTAMP or VARCHAR.

Examples

Create a table and insert sample data:

-- Create a table with TIMESTAMP and VARCHAR timestamp columns.
CREATE TABLE t1(p1 INT, c1 TIMESTAMP, c2 VARCHAR, c3 DOUBLE, PRIMARY KEY(p1));

-- Insert sample rows.
UPSERT INTO t1(p1, c1, c2, c3) VALUES
(1, '2025-01-01 08:30:00',          '2025-01-01 08:30:00',          '12.24'),
(2, '1970-01-01 08:00:00.123',      '1970-01-01 08:00:00.123',      '10.32'),
(3, '1970-01-01 08:00:10.13579',    '1970-01-01 08:00:10.13579',    '10.12'),
(4, '1970-01-01 08:00:10.123456789','1970-01-01 08:00:10.123456789','17.33');

Example 1: Query UNIX timestamps from a table

TIMESTAMP values (c1) retain 3 decimal places; VARCHAR values (c2) retain up to 6.

SELECT p1, UNIX_TIMESTAMP(c1), UNIX_TIMESTAMP(c2) FROM t1;

Output:

+----+------------+------------+
| p1 | EXPR$1     | EXPR$2     |
+----+------------+------------+
| 1  | 1735691400 | 1735691400 |
| 2  | 0.123      | 0.123      |
| 3  | 10.135     | 10.13579   |
| 4  | 10.123     | 10.123457  |
+----+------------+------------+

Example 2: Filter rows using UNIX_TIMESTAMP in a WHERE clause

Count rows where the UNIX timestamp of c1 exceeds 10:

SELECT COUNT(*) FROM t1 WHERE UNIX_TIMESTAMP(c1) > 10;

Output:

+--------+
| EXPR$0 |
+--------+
| 3      |
+--------+

Example 3: Write a UNIX_TIMESTAMP result to a DOUBLE column

Use UNIX_TIMESTAMP in a VALUES clause to write the result directly to the c3 DOUBLE column:

UPSERT INTO t1(p1, c3) VALUES(1, UNIX_TIMESTAMP('1970-01-01 08:00:00.123'));

To verify the result, run:

SELECT * FROM t1;

Format specifiers

The following format specifiers are supported by DATE_FORMAT and FROM_UNIXTIME.

Important

Characters in the format string that do not start with % are returned as-is.

SpecifierOutputDescription
%aSun to SatAbbreviated weekday name.
%bJan to DecAbbreviated month name.
%c0 to 12Month as a numeric value.
%D1st, 2nd, 3rd...Day of the month with ordinal suffix.
%d00 to 31Day of the month, two digits.
%e00 to 31Day of the month, two digits.
%f000000 to 999999Microseconds.
%H00 to 23Hour in 24-hour clock, two digits.
%h01 to 12Hour in 12-hour clock, two digits.
%I01 to 12Hour in 12-hour clock, two digits.
%i00 to 59Minutes, two digits.
%j001 to 366Day of the year, three digits.
%k0 to 23Hour in 24-hour clock, numeric.
%l1 to 12Hour in 12-hour clock, numeric.
%MJanuary to DecemberFull month name.
%m01 to 12Month, two digits.
%pAM or PMAM/PM indicator.
%rhh:mm:ss AM/PMTime in 12-hour clock format.
%S00 to 59Seconds, two digits.
%s00 to 59Seconds, two digits.
%Thh:mm:ssTime in 24-hour clock format.
%WSunday to SaturdayFull weekday name.
%w0 to 6Day of the week as a number. 0 = Sunday, 1 = Monday.
%YFour-digit yearExample: 2025.
%yTwo-digit yearBased on the last two digits of the year. Example: 24 for 2024.
%%%A literal percent sign.
%xxAny letter that is not a reserved specifier, returned as-is. Example: %U returns U.