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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -