Home > Net >  PHP MySQL STR_TO_DATE
PHP MySQL STR_TO_DATE

Time:04-07

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!

CodePudding user response:

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

  • Related