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
xxxxxxxxxx
1
SELECT TIMESTAMP('date_expression', 'time_expression') AS 'alias_name';
Query:
xxxxxxxxxx
1
SELECT TIMESTAMP('2021-01-01', '11:41:31') AS 'new_timestamp';
Result:

date
, time
and timestamp
can be strored as variables.
xxxxxxxxxx
1
SET @date := '2021-01-01';
2
SET @time := '11:41:31';
3
4
SET @timestamp := TIMESTAMP(@date, @time);
5
6
SELECT @timestamp AS `new_timestamp`