Curriculum
Course: MYSQL
Login

Curriculum

MYSQL

MySQL References

0/140
Text lesson

EXTRACT

Example

Extract the month from a given date.

SELECT EXTRACT(MONTH FROM “2017-06-15”);

Definition and Usage

The EXTRACT() function retrieves a specific part from a given date.

Syntax

EXTRACT(part FROM date)

Parameter Values

Parameter

Description

Part

Required. The part to extract, which 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 from which to extract a part.

Technical Details

Works in:

 From MySQL version 4.0

More Examples

Example

Extract the week from a given date.

SELECT EXTRACT(WEEK FROM “2017-06-15”);

Example

Extract the minute from a given datetime.

SELECT EXTRACT(MINUTE FROM “2017-06-15 09:34:21”);

Example

Extract the year and month from a given datetime.

SELECT EXTRACT(YEAR_MONTH FROM “2017-06-15 09:34:21”);