MySQL - need to update column with details from another column in same table.

Hi,
I have an orders table with a 'date_ordered' column that contains dates in the format dd/mm/yyyy - examples  - 21/07/2013, 18/07/2013, 01/02/2012

I have now added a new column called `mysql_date_ordered`, is there a way to update this column using the data from the date_ordered column?

Thanks



--
-- Table structure for table `orders`
--

CREATE TABLE IF NOT EXISTS `orders` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `date_ordered` varchar(15) default NULL,
  `mysql_order_date` datetime NOT NULL default '0000-00-00 00:00:00',
  `user_id` int(10) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
sabecsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ArgentiCommented:
Run this in your MySQL query editor
UPDATE orders
SET mysql_order_date = DATE(concat(right(date_ordered, 4), '-', mid(date_ordered, 4, 2), '-', left(date_ordered, 2)))
WHERE date_ordered is not NULL

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sabecsAuthor Commented:
Thanks Argenti, that is perfect, very much appreciated..
0
ArgentiCommented:
You're welcome
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.