Creating DATETIME from DATE and TIME

前端 未结 6 1453
后悔当初
后悔当初 2020-12-05 04:23

Is there way in MySQL to create DATETIME from a given attribute of type DATE and a given attribute of type TIME?

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-05 04:46

    Without creating and parsing strings, just add an interval to the date:

    set @dt_text = '1964-05-13 15:34:05.757' ;
    set @d = date(@dt_text) ;
    set @t = time(@dt_text) ;
    select @d, @t, @d + interval time_to_sec( @t ) second;
    

    However this truncates the microseconds.

    I agree with Muki - be sure to take account of time zones and daylight savings time!

提交回复
热议问题