Select*fromdate_testing;+------------+|Date |+----------- -+|2017-03-15||2017-03-25||2017-04-05|+----------------+3rowsinset(0."/> Select*fromdate_testing;+------------+|Date |+----------- -+|2017-03-15||2017-03-25||2017-04-05|+----------------+3rowsinset(0.">
We need to use the DATE_FORMAT() function to display the date in other formats. This function takes two parameters, the first is the date and the second is the format string.
Example - Suppose in the table "date_testing" we have three dates in the following format
mysql> Select * from date_testing; +------------+ | Date | +------------+ | 2017-03-15 | | 2017-03-25 | | 2017-04-05 | +------------+ 3 rows in set (0.00 sec)
Now the DATE_FORMAT() function will change the above dates as per the format given by the user The format is as follows -
mysql> Select DATE_FORMAT(Date, '%W %D %M %Y')AS 'FORMATTED DATE' from date_testing; +---------------------------+ | FORMATTED DATE | +---------------------------+ | Wednesday 15th March 2017 | | Saturday 25th March 2017 | | Wednesday 5th April 2017 | +---------------------------+ 3 rows in set (0.00 sec)
In the above example, %W, %D, etc. are date format characters.
The above is the detailed content of In MySQL, how to display dates in other user-specified formats?. For more information, please follow other related articles on the PHP Chinese website!