bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/SQL/SQL References
SQL•SQL References

MySQL EXTRACT() Function

Concept visual

MySQL EXTRACT() Function

Pointer walk
two pointers
leftright102132436485116
left=0
right=6
1
3

Start at both ends

Example

Extract the month from a date:

SELECT EXTRACT(MONTH FROM "2017-06-15");

Definition and Usage

The EXTRACT() function extracts a part from a given date.

Syntax

Extract(

part

From

date )

Parameter Values

Parameter

Description part

Required. The part to extract. Can be one of the following: MICROSECOND SECOND MINUTE HOUR DAY WEEK MONTH QUARTER

Year

SECOND_MICROSECOND MINUTE_MICROSECOND MINUTE_SECOND HOUR_MICROSECOND HOUR_SECOND HOUR_MINUTE DAY_MICROSECOND DAY_SECOND DAY_MINUTE DAY_HOUR YEAR_MONTH date Required. The date to extract a part from

Technical Details

Works in:

From MySQL 4.0

More Examples

Example

Extract the week from a date:

SELECT EXTRACT(WEEK FROM "2017-06-15");

Example

Extract the minute from a datetime: SELECT EXTRACT(MINUTE FROM "2017-06-15 09:34:21");

Example

Extract the year and month from a datetime: SELECT EXTRACT(YEAR_MONTH FROM "2017-06-15 09:34:21");

Previous

❮ MySQL Functions

Next

Previous

MySQL DAYOFYEAR() Function

Next

MySQL FROM_DAYS() Function