Home > Database > Mysql Tutorial > body text

How to apply EXTRACT() function to dates stored in MySQL table?

PHPz
Release: 2023-08-23 18:25:02
forward
548 people have browsed it

如何对 MySQL 表中存储的日期应用 EXTRACT() 函数?

We can apply the EXTRACT() function on the dates stored in the MySQL table in the following way -

The following query displays the dates entered in the table "testing"

mysql> Select * from testing;
+-------------+---------------------+
| StudentName | Dateofreg           |
+-------------+---------------------+
| Ram         | 2017-10-28 21:24:24 |
| Shyam       | 2017-10-28 21:24:30 |
| Mohan       | 2017-10-28 21:24:47 |
| Gaurav      | 2017-10-29 08:48:33 |
+-------------+---------------------+
4 rows in set (0.00 sec)
Copy after login

Now, we can apply the EXTRACT() function on the "testing" table to get the year value, as follows-

mysql> Select EXTRACT(Year from dateofreg)AS YEAR from testing;
+------+
| YEAR |
+------+
| 2017 |
| 2017 |
| 2017 |
| 2017 |
+------+
4 rows in set (0.00 sec)
Copy after login

Similarly, we can apply the EXTRACT() function on the "testing" table to Get the date value as follows-

mysql> Select EXTRACT(day from dateofreg)AS DAY from testing;
+-----+
| DAY |
+-----+
| 28  |
| 28  |
| 28  |
| 29  |
+-----+
4 rows in set (0.00 sec)
Copy after login

The above is the detailed content of How to apply EXTRACT() function to dates stored in MySQL table?. 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