Mysql
 SQL >> Database >  >> RDS >> Mysql

Formattare un campo data MySQL in PHP

Se in PHP la chiave non è birthdate ma l'espressione DATE_FORMAT(...), aggiungi un alias:

SELECT DATE_FORMAT(birthdate, '%m-%d-%Y') AS birthdate, name
FROM persons
ORDER BY name DESC;

In alternativa, seleziona il valore grezzo e formattalo in PHP:

SELECT UNIX_TIMESTAMP(birthdate) AS birthdate, name FROM persons;

Formatare in PHP mantiene la logica di presentazione fuori da SQL.