Home > Database > Mysql Tutorial > body text

In MySQL, how to display dates in other user-specified formats?

PHPz
Release: 2023-09-08 11:41:07
forward
903 people have browsed it

In MySQL, how to display dates in other user-specified formats?

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)
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!