How to change the date format when querying in MySQL, I write the date into the database via NOW ()
and it has the format YYYY-MM-DD HH-MM-SS
, to me you need the date to be in the d: m: YH: i
format when the record is received.
To do this, I make a request using
DATE_FORMAT (): SELECT * DATE_FORMAT (date, '% d /% m /% Y% H:% i') FROM comm.
But the date is still in the form YYYY-MM-DD HH-MM-SS
. What is the mistake?
Answer 1, authority 100%
What type of field? There should be DateTime
, and this is how your function works fine:
SELECT DATE_FORMAT ('2018-07-25 18:01:02', '% d /% m /% Y% H:% i ')
Result:
07/24/2018 05:03
Answer 2, authority 100%
php has a great date function: http://php.net/manual/ ru / function.date.php . By installing the desired filter, you will get the desired result.
date ("D.m.Y", strtotime ($ datetime))