MySQL DATETIME - Change only the date

后端 未结 6 1099
执笔经年
执笔经年 2020-12-28 17:03

Starting with : 2011-01-17 09:30:00

Let\'s say I want to edit just the date with 2011-01-28

What is the most efficient way to end up with: 2011-01-28 09:30:0

相关标签:
6条回答
  • 2020-12-28 17:37

    You can add various components of a date to modify it using the Date_Add function. Check this out:

    http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-add

    0 讨论(0)
  • 2020-12-28 17:38

    Check Query

     update yourtable set eventtime=replace(eventtime,substr(eventtime,1,10), '2013-07-17')  WHERE  `id`=4
    
    0 讨论(0)
  • 2020-12-28 17:39

    Probably, DATE_ADD is a good idea. link text

    0 讨论(0)
  • 2020-12-28 17:41

    If you really don't want to use date_add function, you can consider using this construction:

    UPDATE table_name SET field_name = concat('2011-01-12 ', time(field_name)) 
    

    Make sure to add a space after the date ('2011-01-12').

    0 讨论(0)
  • 2020-12-28 17:48

    To change it 5 days ahead:

    UPDATE yourTableName
    SET myDate1 = myDate1 + INTERVAL 5 DAY
    WHERE myDate1 = dateIWantToChange
    

    (you can use MONTH, YEAR, etc too)

    0 讨论(0)
  • 2020-12-28 17:54

    Going to use something like:

    CONCAT('2011-01-28 ',DATE_FORMAT(original_timestamp, '%H:%i:%s'))
    
    0 讨论(0)
提交回复
热议问题