Home >Database >Mysql Tutorial >How to implement date formatting in MySQL

How to implement date formatting in MySQL

PHPz
PHPzforward
2023-05-28 22:04:044174browse

Date formatting

Command: select date_format(now(),'%y-%m-%d).

Function: Format date.

Application scenario: When formatting dates.

Example:

mysql> select date_format(now(),'%y-%m-%d');
+-------------------------------+
| date_format(now(),'%y-%m-%d') |
+-------------------------------+
| 17-12-28   |
+-------------------------------+
1 row in set (0.00 sec)

The formats supported here are:

%y: represents the year (two digits), for example: 17 years.
%Y: Indicates the 4-digit year, for example: 2017
%m: Indicates the month (1-12)
%d: Indicates the day in the month
%H: Hour ( 0-23)
%i: minutes (0-59)
%s: seconds (0-59)

Year, month, day, hour, minute and second: %y-%m-%d %H :%i:%s,

looks like this:

mysql> select DATE_FORMAT(now(),'%y-%m-%d %H:%i:%s');
+----------------------------------------+
| DATE_FORMAT(now(),'%y-%m-%d %H:%i:%s') |
+----------------------------------------+
| 17-12-27 20:28:54   |
+----------------------------------------+
1 row in set (0.00 sec)

The above is the detailed content of How to implement date formatting in MySQL. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete