
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to apply EXTRACT() function on the dates stored in MySQL table?
We can apply EXTRACT() function on the dates stored in MySQL table in the following way −
The following query is showing what dates are entered in 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 EXTRACT() function, to obtain the value of the year, on ‘testing’ table 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 EXTRACT() function, to obtain the value of day, on ‘testing’ table as follows −
mysql> Select EXTRACT(day from dateofreg)AS DAY from testing; +-----+ | DAY | +-----+ | 28 | | 28 | | 28 | | 29 | +-----+ 4 rows in set (0.00 sec)
- Related Articles
- How to apply EXTRACT() function with WHERE Clause on the dates stored in MySQL table?
- How can I convert the epoch stored in MySQL table into readable dates?
- How can we apply BIT_LENGTH() function on the column/s of MySQL table?
- How to write a MySQL stored function that updates the values in a table?
- How to write a MySQL stored function that inserts values in a table?
- Searching BETWEEN dates stored as varchar in MySQL?
- Extract gender values as a string when it is stored in the table as a Boolean in MySQL
- Perform MySQL SELECT on dates inserted into the table as VARCHAR values
- How can we apply COALESCE() function on a MySQL table’s data value?
- Update table and order dates in MySQL
- How can we create a MySQL stored function that uses the dynamic data from a table?
- Apply MySQL query to each table in a database?
- How to delete the duplicate values stored in reverse order from MySQL table?
- How to repeat the values stored in a data column of MySQL table?
- MySQL Stored Procedure to create a table?

Advertisements