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');
精彩评论