Skip to main content

TIMESTAMP

Description

The TIMESTAMP function has two uses:

  1. Convert a datetime string to a DATETIME type
  2. Combine two arguments into a DATETIME type

Syntax

TIMESTAMP(string)
TIMESTAMP(date, time)

Parameters

ParameterDescription
stringA datetime string
dateA date value, which can be a DATE type or a properly formatted date string
timeA time value, which can be a TIME type or a properly formatted time string

Return Value

Returns a value of type DATETIME.

Example

-- 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 |
+------------------------------------+
-- Combine date and time into DATETIME
SELECT TIMESTAMP('2019-01-01', '12:00:00');
+----------------------------------------+
| timestamp('2019-01-01', '12:00:00') |
+----------------------------------------+
| 2019-01-01 12:00:00 |
+----------------------------------------+