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

How to implement date formatting in MySQL

PHPz
Release: 2023-05-28 22:04:04
forward
4177 people have browsed it

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

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

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!

Related labels:
source:yisu.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