* Wong Zach-CHZ013
[...]
> In table a, the columns are
> my_date - longtext
> num - int(11)
[...]
> Q:
> How do I convert 08/06/2002 to 2002-08-06 format

LONGTEXT is not a good column type for dates, you should use the special
'date' type, see <URL: http://www.mysql.com/doc/en/Column_types.html >.

To change the table a, adding a new date column:

ALTER TABLE a ADD new_date date;

Updating the new column with dates from the old:

UPDATE a SET new_date =
CAT( 
  MID(my_date,7,4),'-',
  MID(my_date,1,2),'-',
  MID(my_date,4,2));

Finally, after checking the result, you may want to drop the old column and rename the 
new one, and you can use ALTER TABLE for this too:

ALTER TABLE a DROP my_date;
ALTER TABLE a CHANGE new_date my_date date;

<URL: http://www.mysql.com/doc/en/ALTER_TABLE.html >
<URL: http://www.mysql.com/doc/en/UPDATE.html >

HTH,

-- 
Roger


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to