EN
MySQL - combine DATE and TIME into TIMESTAMP
3
points
In this article, we would like to show you how to combine DATE
and TIME
into TIMESTAMP
in MySQL.
Quick solution
SELECT TIMESTAMP('date_expression', 'time_expression') AS 'alias_name';
Practical example
Query:
SELECT TIMESTAMP('2021-01-01', '11:41:31') AS 'new_timestamp';
Result:
Variables based example
date
, time
and timestamp
can be strored as variables.
SET @date := '2021-01-01';
SET @time := '11:41:31';
SET @timestamp := TIMESTAMP(@date, @time);
SELECT @timestamp AS `new_timestamp`