I'm trying to format the date in MySQL but I can't, the date format is as follows:
05-08-2017 - 18:03
I want to transform it to
2018-11-09 - 20:30
Wearing
SELECT DATE_FORMAT(STR_TO_DATE(fecha, '%d-%m-%Y - %H:%i'), '%Y-%m-%d -
%H:%i') WHERE id = 92
Am I using the STR_TO_DATE and the DATE_FORMAT correctly?
Thank you
Edit: Correct, the FROM silly bug was missing that I didn't realize, then to update I used the UPDATE and that's it, thank you all
UPDATE tabla SET fecha = DATE_FORMAT(STR_TO_DATE(fecha, '%d-%m-%Y %H:%i'), '%Y-%m-%d - %H:%i') WHERE id = ?
Your query is correct, of course, if:
FROM
It is assumed that you will also add an alias to the resulting column.
And, if your column were of type
DATE
orDATETIME
not you would needSTR_TO_DATE
. If it is of the typeVARCHAR
and you can normalize , then do so.The query like this should work without problem:
Your query is perfect, except that it is missing the FROM of the table, but if you do this test:
works fine, returns
Greetings.