

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What kind of compound units can be used in MySQL EXTRACT() function?
MySQL EXTRACT() function can use following compound units −
- SECOND_MICROSECOND
- MINUTE_MICROSECOND
- HOUR_MICROSECOND
- DAY_MICROSECOND
- MINUTE_SECOND
- HOUR_SECOND
- HOUR_MINUTE
- DAY_SECOND
- DAY_MINUTE
- DAY_HOUR
- YEAR_MONTH
Some of the examples of these compound units used in EXTRACT() function are as follows −
mysql> Select EXTRACT(YEAR_MONTH from '2017-10-20'); +---------------------------------------+ | EXTRACT(YEAR_MONTH from '2017-10-20') | +---------------------------------------+ | 201710 | +---------------------------------------+ 1 row in set (0.00 sec)
Above query will return the year and month value from the date.
mysql> Select EXTRACT(DAY_HOUR from '2017-10-20 05:46:45'); +----------------------------------------------+ | EXTRACT(DAY_HOUR from '2017-10-20 05:46:45') | +----------------------------------------------+ | 2005 | +----------------------------------------------+ 1 row in set (0.00 sec)
Above query will return the day and hour value from a date.
One thing we must have to take into consideration that the above-mentioned compound units are a complete set of values i.e. if we will use DAY_MINUTE, MySQL returns the DAY, HOUR and MINUTE. It means that any value that would normally be expected is filled in between a start and end unit.
For example, the below query is using DAY_MICROSECOND compound unit and MySQL returns the DAY, HOUR, MINUTE, SECOND and MICROSECOND. It means that the values of HOUR, MINUTE and SECOND are filled in between DAY and MICROSECOND.
mysql> Select EXTRACT(DAY_MICROSECOND from '2017-10-22 05:52:45.102356'); +---------------------------------------------------------------------------+ | EXTRACT(DAY_MICROSECOND from '2017-10-22 05:52:45.102356') | +---------------------------------------------------------------------------+ | 22055245102356 | +---------------------------------------------------------------------------+ 1 row in set (0.00 sec)
- Related Questions & Answers
- What kind of SQL statements can be used to prepare statements?
- How Groups function can be used in MySQL SELECT clause?
- What kind of string comparison, case-sensitive or not, can be performed by MySQL?
- How LOCATE() function can be used with MySQL WHERE clause?
- How can MySQL REPLACE() function be used with WHERE clause?
- How can CONCAT() function be used with MySQL WHERE clause?
- How wildcard characters can be used with MySQL CONCAT() function?
- How can CONCAT_WS() function be used with MySQL WHERE clause?
- What kind of indexing can be done on a PostgreSQL table?
- What function in MySQL can be used to get the number code of a specific character?
- How can MySQL COALESCE() function be used with MySQL SUM() function to customize the output?
- What names can be used in plt.cm.get_cmap?
- How can MySQL SUBSTRING() function be used with FROM and FOR keywords?
- Can we enforce compound uniqueness in MySQL?
- Which MySQL function can be used to append values of a column with single quotes?