Unix Technical Forum

Fill new column with data from other columns

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 ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 08:50 AM
Salve =?iso-8859-1?Q?H=E5kedal?=
 
Posts: n/a
Default Fill new column with data from other columns

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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 08:50 AM
Paul Lautman
 
Posts: n/a
Default Re: Fill new column with data from other columns

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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:59 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com