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

PHP MySQL STR_TO_DATE

For some reasons my date is saved in a varchar field in my mysql database table. It’s in the format e.g. 06.04.2022 15:20:00. I would like to execute the following SQL statement:

SELECT * FROM Files WHERE Aktenzeichen = '55/22' ORDER BY STR_TO_DATE(`Uhrzeit`,'%d.%M.%Y %H:%i:%s') DESC

It’s not sorting the values correctly. Any hints?

Kindest regards!

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 :

No, M stands for Month as name

and test you can always run a simple select.

Still, this will always cost a lot of time and resources, so save the date in a mysql format always

SELECT STR_TO_DATE('06.04.2022 15:20:00','%d.%m.%Y %H:%i:%s')
| STR_TO_DATE('06.04.2022 15:20:00','%d.%m.%Y %H:%i:%s') |
| :----------------------------------------------------- |
| 2022-04-06 15:20:00                                    |

db<>fiddle here

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