Home > Database > Mysql Tutorial > How to get part of date in MySQL?

How to get part of date in MySQL?

WBOY
Release: 2023-08-23 19:13:15
forward
1081 people have browsed it

How to get part of date in MySQL?

By using EXTRACT() function we can get the current date or part of a given date. Parts of the date can be obtained as year, month, day, hour, minute, second, and microsecond.

Example

mysql> Select EXTRACT(Year from NOW()) AS YEAR;
+-------+
| YEAR  |
+-------+
|   2017|
+-------+
1 row in set (0.00 sec)
Copy after login

The above MySQL query will get the year from the current date.

mysql> Select EXTRACT(Month from '2017-09-21')AS MONTH;
+-------+
| MONTH |
+-------+
|     9 |
+-------+
1 row in set (0.00 sec)
Copy after login

The above MySQL query will get the month for a given date.

The above is the detailed content of How to get part of date in MySQL?. 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