Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to convert a date varchar string with a different date format to MySQL date format?

We imported a table, most probably from an Excel file, where a DATETIME, saved in a varchar, has a format that looks like this:

12/06/2003 07:42

Is there any way to convert that into a valid MySQL date format for later convert the field from varchar to DATETIME? Maybe with a regular expression? Note that 12 is the day and 06 the month.

2003-06-12 07:42:00

Thanks

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You would use str_to_date for this:

select str_to_date('12/06/2003 07:42','%d/%m/%Y %H:%i')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading