MySql, combining date and time column into a time stamp

前端 未结 6 1356
孤城傲影
孤城傲影 2020-12-14 14:32

I am guessing this is relatively simple to do, but I am unsure of the syntax. I have date and time columns that I want to combine to a timestamp column. how would I query th

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-14 15:07

    Mysql does not seem to have a constructor for datetime such as datetime('2017-10-26', '09:28:00'). So you will have to treat the component part as string and use string concatenation function (Note mysql does not have the || operator for string concatenation). If you want the datetime type, you will have to cast it.

    concat(datefield,' ',timefield) as date
    
    select cast(concat('2017-10-26', ' ', '09:28:00') as datetime) as dt;
    

提交回复
热议问题