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");


Login
ADS CODE