MySQL TIMESTAMP() Function
The TIMESTAMP()
function in MySQL creates a datetime value. You can use it to build datetime values from separate date and time components or to modify an existing datetime by adding a time interval.
TIMESTAMP(): Definition and Usage
TIMESTAMP()
is very useful for constructing or adjusting datetime values. When given a single argument (a date or datetime), it simply returns that value. When given two arguments (a date and a time), it combines them into a single datetime value. If the second argument is a time interval, it adds this to the first argument (date or datetime).
Syntax
Syntax
TIMESTAMP(expression, time)
Parameter Values
Parameter | Description |
---|---|
expression |
A date or datetime value. This is required. |
time (Optional) |
A time value or time interval to add to the expression . If omitted, only the expression is returned. |
Examples
Creating a DATETIME from Date and Time
This example combines a date and a time to create a datetime value.
Syntax
SELECT TIMESTAMP("2017-07-23", "13:10:11");
Output
2017-07-23 13:10:11
Using Only a Date
If you provide only a date, the time portion will be 00:00:00.
Syntax
SELECT TIMESTAMP("2017-07-23");
Output
2017-07-23 00:00:00