TIMESTAMP
Description
The TIMESTAMP function converts a date-time string to DATETIME. For a TIMESTAMP_NS input, it returns TIMESTAMP_NS and preserves nanosecond precision. If a second time parameter is provided, it adds that time value to the first parameter and preserves the first parameter's corresponding date-time type.
For specific datetime formats, please refer to datetime conversion.
This function behaves the same way as the timestamp function in MySQL.
Syntax
TIMESTAMP(<date_or_datetime_string>[, <time_string>])
Parameters
| Parameter | Description |
|---|---|
date_or_datetime_string | A date or datetime string, or a DATETIME or TIMESTAMP_NS expression. |
time_string | Time string type |
Return Value
A TIMESTAMP_NS input returns TIMESTAMP_NS with fixed nine-digit fractional-second precision. Results are validated against the range of the return type; TIMESTAMP_NS uses its range of [1677-09-21 00:12:43.145224192, 2262-04-11 23:47:16.854775807].
Returns DATETIME for date, datetime, and string input, and returns TIMESTAMP_NS for TIMESTAMP_NS input.
When one parameter is provided, returns the first parameter as the corresponding datetime type. When two parameters are provided, returns the sum of the two parameters.
- If the first parameter is a date string, the time is set to 00:00:00
- If any parameter is NULL or parameter type does not match, returns NULL
Examples
-- Convert a string to DATETIME
SELECT TIMESTAMP('2019-01-01 12:00:00');
+------------------------------------+
| timestamp('2019-01-01 12:00:00') |
+------------------------------------+
| 2019-01-01 12:00:00 |
+------------------------------------+
-- Input date string
SELECT TIMESTAMP('2019-01-01');
+-------------------------+
| TIMESTAMP('2019-01-01') |
+-------------------------+
| 2019-01-01 00:00:00 |
+-------------------------+
-- Input NULL, returns NULL
SELECT TIMESTAMP(NULL);
+-----------------+
| TIMESTAMP(NULL) |
+-----------------+
| NULL |
+-----------------+
-- Two parameters, returns the sum of the two parameters (Date/DateTime + Time)
SELECT TIMESTAMP('2025-11-30 23:45:12', '12:34:56');
+----------------------------------------------+
| TIMESTAMP('2025-11-30 23:45:12', '12:34:56') |
+----------------------------------------------+
| 2025-12-01 12:20:08 |
+----------------------------------------------+
-- The first parameter only accepts Date/Datetime type, the second parameter only accepts Time type
SELECT TIMESTAMP('12:34:56', '12:34:56');
+-----------------------------------+
| TIMESTAMP('12:34:56', '12:34:56') |
+-----------------------------------+
| NULL |
+-----------------------------------+
-- If any parameter is NULL, returns NULL
SELECT TIMESTAMP('2025-12-01', NULL);
+-------------------------------+
| TIMESTAMP('2025-12-01', NULL) |
+-------------------------------+
| NULL |
+-------------------------------+