开发者

Rails mysql how to change time on mulitple columns at once?

In my table I have a column dato that hold a datetime:

2011-04-12 10:37:07
2011-04-12 10:31:07
2011-04-10 10:32:07
2011-04-11 10:45:07
2011-04-12 10:37:07

I want to change all of the dato columns hour to 00:开发者_开发百科00:00

How is it done?


You can do this with the following query

UPDATE <table> SET <date column>= DATE(<date column>);

E.g.

UPDATE Customer SET startDate = DATE(startDate);

You can do it from the console using the mysql tool.


See Update multiple records simultaneously with ActiveRecord in Rails using one query?


I believe you want to alter multiple records rather than columns. Anyway:

UPDATE mytable
SET dato = DATE_FORMAT(dato, '%Y-%m-%d 00:00:00');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜