Languages
[Edit]
EN

MySQL - combine DATE and TIME into TIMESTAMP

3 points
Created by:
Dirask Community
6240

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

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