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


/ Published in: MySQL
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.