Languages
[Edit]
EN

MySQL - combine DATE and TIME into TIMESTAMP

3 points
Created by:
Teilsa
1105

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:

MySQL - combine DATE and TIME into TIMESTAMP - result
MySQL - combine DATE and TIME into 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`

Related posts

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

MySQL - dates

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join