This is a discussion on Fill new column with data from other columns within the MySQL forums, part of the Database Server Software category; --> I'm going to add a new column to a table, and the table has a lot of records like ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I'm going to add a new column to a table, and the table has a lot of records like this: +------+--------+------+ | year | month | day | +------+--------+------+ | 2004 | 10 | 24 | +------+--------+------+ I know how to add the new column, but: The new column should be of type date; that is contain the above data in this form: '2004-10-24', so I'll be able to do calculations on the dates. Is there a way to build that date string with mysql statements alone, or is it better to apply a php-script to do this? |
| ||||
| Salve Håkedal wrote: > I'm going to add a new column to a table, and the table has a lot of > records like this: > > +------+--------+------+ >> year | month | day | > +------+--------+------+ >> 2004 | 10 | 24 | > +------+--------+------+ > > I know how to add the new column, but: > The new column should be of type date; that is contain the above data > in this form: '2004-10-24', so I'll be able to do calculations on the > dates. > > Is there a way to build that date string with mysql statements alone, > or is it better to apply a php-script to do this? You can either concatenate the fields into a supported date string or use the STR_TO_DATE function |