- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)
Advertisements