MySQL DATETIME - 仅更改日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4695117/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 18:20:02  来源:igfitidea点击:

MySQL DATETIME - Change only the date

mysql

提问by Michael

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

开始于:2011-01-17 09:30:00

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

假设我只想用 2011-01-28 编辑日期

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

什么是最有效的结束方式:2011-01-28 09:30:00

Thanks!

谢谢!

For everyone saying Date_Add... that would require me to subtract the dates, then add the days. Thats a possibility... but was looking to remove that first step, and just "replace" the date

对于每个说 Date_Add ... 的人来说,这需要我减去日期,然后加上天数。那是一种可能性......但正在寻求删除第一步,而只是“替换”日期

回答by itsmeee

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

如果你真的不想使用 date_add 函数,你可以考虑使用这个构造:

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?').

确保在日期后添加一个空格 ( '2011-01-12 ?')。

回答by rownage

To change it 5 days ahead:

要提前 5 天更改:

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

(you can use MONTH, YEAR, etc too)

(您也可以使用 MONTH、YEAR 等)

回答by Paul

Probably, DATE_ADD is a good idea. link text

可能, DATE_ADD 是个好主意。链接文字

回答by Krishna-Winnou systems

Check Query

检查查询

 update yourtable set eventtime=replace(eventtime,substr(eventtime,1,10), '2013-07-17')  WHERE  `id`=4

回答by Michael

Going to use something like:

将使用类似的东西:

CONCAT('2011-01-28 ',DATE_FORMAT(original_timestamp, '%H:%i:%s'))

回答by Raj More

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

您可以使用 Date_Add 函数添加日期的各种组件以对其进行修改。看一下这个:

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

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