sql date_format number code example

Example 1: mysql format date

DATE_FORMAT(date, format)
-- E.g.
SELECT DATE_FORMAT(dateField, '%m/%d/%Y') FROM TableName;
-- See https://www.mysqltutorial.org/mysql-date_format/ for available formats

Example 2: DATE_FORMAT(STR_TO_DATE

mysql> Select * from date_testing1;
+-------+------------+
| Name | Date        |
+-------+------------+
| Ram   | 2017-05-03 |
| Shyam | 2003-10-31 |
+-------+------------+
2 rows in set (0.07 sec)

mysql> Select Name, Date, DATE_FORMAT(date,GET_FORMAT(date,'USA'))AS 'DATE IN US FORMAT'from date_testing1 Where Name='Ram';
+------+------------+-------------------+
| Name | Date       | DATE IN US FORMAT |
+------+------------+-------------------+
| Ram | 2017-05-03  | 05.03.2017        |
+------+------------+-------------------+
1 row in set (0.00 sec)