mysql - How to update date and hour, while keeping Minutes and Seconds -
i have datetime 0000-00-00 00:00:00
column in table,
need keep minute , seconds when updating ____-__-__ __:mm:ss
change date , hour current time.
how can achieve on mysql side?
edit (sample):
current date field value: 2016-06-27 15:13:07
we update table @ 2016-07-28 12:31:18
desired date field value: 2016-07-28 12:13:07
as can see updated date still has correct 2016-07-28 12:
:13:07
(minutes , seconds) selected date before update , replaced current time's minutes , seconds
you can make use of mysql concat() function.
update query looks this,
update table_name set date_column = concat('2016-06-29 15:',minute(date_column),':',second(date_column)) column_id = 1
concat() returns string results concatenating given arguments.
so in case update date , hour adding first argument 2016-06-29 15:
, , use same minute , second same column. , concatenate arguments make new value need.
http://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_concat
Comments
Post a Comment