Skip to content

TIMESTAMP()

Function Description

TIMESTAMP() returns the date or datetime expression expr as the datetime value for a single parameter. When two parameters are used, TIMESTAMP() adds the time expression expr2 to the date or datetime expression expr1 and returns the result as a datetime value. If expr, expr1 or expr2 is NULL, NULL is returned.

Function Syntax

> TIMESTAMP(expr), TIMESTAMP(expr1,expr2)

Parameter definition

Parameters Description
expr Required parameters. The expr parameter is the time interval that needs to be added to date. If expr is a negative number, it can start with "-".

Example

mysql> SELECT TIMESTAMP('2003-12-31');
+----------------------------------+
| timestamp(2003-12-31) |
+----------------------------------+
| 2003-12-31 00:00:00.000000 |
+----------------------------------+
1 row in set (0.00 sec)
CREATE TABLE t1(c1 DATE NOT NULL);
INSERT INTO t1 VALUES('2000-01-01');
INSERT INTO t1 VALUES('1999-12-31');
INSERT INTO t1 VALUES('2000-01-01');
INSERT INTO t1 VALUES('2006-12-25');
INSERT INTO t1 VALUES('2008-02-29');

mysql> SELECT TIMESTAMP(c1) FROM t1;
+----------------------------------+
| timestamp(c1) |
+----------------------------------+
| 2000-01-01 00:00:00.000000 |
| 1999-12-31 00:00:00.000000 |
| 2000-01-01 00:00:00.000000 |
| 2006-12-25 00:00:00.000000 |
| 2008-02-29 00:00:00.000000 |
+----------------------------------+
5 rows in set (0.00 sec)

limit

TIMESTAMP() does not support dual parameters at the moment, that is, TIMESTAMP(expr1,expr2) is not supported.