Posted By

jpkunst on 12/06/11


Tagged

date


Versions (?)

Convert textual dates of the form '[d]d-[m]m-yyyy' to actual dates


 / Published in: MySQL
 

Converts textual dates like '1-3-1954' and '01-02-1963' to respectively '1954-3-1' and '1963-02-01'. MySQL is smart enough to understand the values without leading zeros when inserting into a DATE field.

  1. SELECT CONCAT(SUBSTRING_INDEX(`textual_date`, '-', -1), '-', TRIM('-' FROM MID(`textual_date`, LOCATE('-', `textual_date`) + 1, 2)), '-', SUBSTRING_INDEX(`textual_date`, '-',1)) AS year_month_day FROM table;

Report this snippet  

You need to login to post a comment.