Select*fromtesting;+------------- +---------------------+|StudentName|Dateofreg |+-------------+------ ---------------+|Ram &"/> Select*fromtesting;+------------- +---------------------+|StudentName|Dateofreg |+-------------+------ ---------------+|Ram &">
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)
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)
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)
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!