0

I have a lot of rows in a MySQL database.

One of my columns is called date, and holds dates with values like "May 25", "May 26", "May 27" etc.

I would then like to split the value into two so I have two new columns, like one called day and one called month.

How can this be done?

Thanks in advance

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
madsobel
  • 2,797
  • 3
  • 14
  • 22
  • possible duplicate of [Can Mysql Split a column?](http://stackoverflow.com/questions/1096679/can-mysql-split-a-column) – sgeddes May 26 '14 at 15:37
  • Why wouldn't you like to create a culum with proper data type that lets you format the date any way you like once you pull it out? Why would you save dates in that format and not using industry standards? Why would you make your life as a programmer difficult? – N.B. May 26 '14 at 15:39
  • Unfortunately the data I get is formatted like that. I process a csv file that comes like that. – madsobel May 26 '14 at 16:51

1 Answers1

0

Try this with SUBSTRING_INDEX ,

  Select  SUBSTRING_INDEX(`month`, ' ',  1) as month ,
          SUBSTRING_INDEX(`month`, ' ',  -1) as day from Table1

DEMO HERE

echo_Me
  • 37,078
  • 5
  • 58
  • 78