TIMESTAMP()

Description

With a single argument, this function returns the date or datetime expression expr as a datetime value. With two arguments, it adds the time expression expr2 to the date or datetime expression expr1 and returns the result as a datetime value. Returns NULL if expr, expr1, or expr2 is NULL.

Syntax

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

Arguments

Arguments Description
expr Required. The expr is an expression specifying the interval value to be added or subtracted from the starting date. The expr is evaluated as a string; it may start with a - for negative intervals.

Examples

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

8. mysql> SELECT TIMESTAMP(c1) FROM t1;
9. +----------------------------+
10. | timestamp(c1)              |
11. +----------------------------+
12. | 2000-01-01 00:00:00.000000 |
13. | 1999-12-31 00:00:00.000000 |
14. | 2000-01-01 00:00:00.000000 |
15. | 2006-12-25 00:00:00.000000 |
16. | 2008-02-29 00:00:00.000000 |
17. +----------------------------+
18. 5 rows in set (0.00 sec)

Constraints

TIMESTAMP() does not support double arguments for now, which means it doesn’t support TIMESTAMP(expr1,expr2).