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

How to get part of date in MySQL?

WBOY
WBOYforward
2023-08-23 19:13:151087browse

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)

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)

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!

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