Combining a Date and a Time into a Date-and-Time Value

Problem

You want to produce a combined date-and-time value from separate date and time values.

Solution

Concatenate them with a space in between.

Discussion

Combining a date value and a time value to produce a date-and-time value is just a matter of concatenating them with a space in between:

mysql> SET @d = '2002-02-28';
mysql> SET @t = '13:10:05';
mysql> SELECT @d, @t, CONCAT(@d,' ',@t);
+------------+----------+---------------------+
| @d         | @t       | CONCAT(@d,' ',@t)   |
+------------+----------+---------------------+
| 2002-02-28 | 13:10:05 | 2002-02-28 13:10:05 |
+------------+----------+---------------------+

Get MySQL Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.