Search code examples
mysqlsqldatesql-updatevarchar

Manipulate VARCHAR string and update column (pseudo-date)


So long story short, a client of mine wanted to change a date-time field into a varchar field, after hours of telling them why they should not do that, I finally gave in.

My Issue is the dates now converted into VARCHAR are yyyy-mm-dd and I need to flip them around into mm-dd-yyyy I can do this with PHP with a foreach() loop and a list()=explode() but is there a way to do it with a sql query?


Solution

  • You can use DATE_FORMAT:

    UPDATE your_table SET your_varchar = DATE_FORMAT(your_varchar ,'%m-%d-%Y')
    

    For more information, see the MySQL documentation: DATE_FORMAT