mysql date formatr code example
Example 1: mysql format date
DATE_FORMAT(date, format)
-- E.g.
SELECT DATE_FORMAT(dateField, '%m/%d/%Y') FROM TableName;
-- See https:
Example 2: mysql date format
-- Converts 'dd.mm.yyyy' to date (my_date_col is VARCHAR)
SELECT STR_TO_DATE(my_date_col,'%d.%m.%Y') AS my_strdate FROM my_table;
-- Converts 'dd.mm.yyyy' to 'YYYY-MM-DD'
SELECT DATE_FORMAT(STR_TO_DATE(my_date_col,'%d.%m.%Y'), '%Y-%m-%d') AS my_strdate
FROM my_table;
Example 3: MySQL datetime format
use \Datetime;
$now = new DateTime();
echo $now->format('Y-m-d H:i:s');
echo $now->getTimestamp();