MySQL 在日期时间字段中设置当前日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14197208/
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
Set current date in the datetime field
提问by You Kuper
There is a datetime field in the MySQL table:
MySQL表中有一个日期时间字段:
`mytime` datetime
It contains entries like '2012-02-10 10:15'.
它包含诸如“2012-02-10 10:15”之类的条目。
How to set the date partto the current date?
如何将日期部分设置为当前日期?
回答by Suresh Kamrushi
You can use -
您可以使用 -
update table tblName set mytime = current_date()
Or
或者
update table tblName set mytime =concat(current_date(),' ',TIME(mytime))
回答by John Woo
回答by user1955162
UPDATE table SET mytime = CONCAT(CURDATE(), ' ' , time(mytime)) WHERE id = row;
I think this will work, my syntax may be off. time(mytime)
may give you hour:minute:seconds
while you are only looking for hour:minute
. I think you also need the ' '
in there so MySQL will recognize the time format.
我认为这会奏效,我的语法可能已关闭。time(mytime)
可能给你,hour:minute:seconds
而你只是在寻找hour:minute
。我认为您还需要' '
在那里,以便 MySQL 识别时间格式。
回答by Siddharth Reddy
Use below query..
使用以下查询..
update Table1 set mytime=now();
回答by Fathah Rehman P
suppose your table is as follows
假设你的表如下
CREATE TABLE `table66` (
`id` INT(10) NULL DEFAULT NULL,
`mytime` DATETIME NULL DEFAULT NULL
)
Then you can use following query to update your mytime column
然后您可以使用以下查询来更新您的 mytime 列
update table66 set mytime=concat(date(now()),' ',time(mytime) )
回答by ypercube??
UPDATE test
SET mytime = mytime + INTERVAL DATEDIFF(CURRENT_DATE(),DATE(mytime)) DAY ;