Creating DATETIME from DATE and TIME

Copied from the MySQL Documentation:

TIMESTAMP(expr), TIMESTAMP(expr1,expr2)

With a single argument, this function returns the date or datetime expression expr as a datetime value. With two arguments, it adds the time expression expr2 to the date or datetime expression expr1 and returns the result as a datetime value.

mysql> SELECT TIMESTAMP('2003-12-31');
    -> '2003-12-31 00:00:00'
mysql> SELECT TIMESTAMP('2003-12-31 12:00:00','12:00:00');
    -> '2004-01-01 00:00:00'

To get a true DATETIME value from your two separate DATE and TIME values:

STR_TO_DATE(CONCAT(date, ' ', time), '%Y-%m-%d %H:%i:%s')

You could use ADDTIME():

ADDTIME(CONVERT(date, DATETIME), time)
  • date may be a date string or a DATE object.
  • time may be a time string or a TIME object.

Tested in MySQL 5.5.

Tags:

Datetime

Mysql