Open In App

EXTRACT() Function in MySQL

Last Updated : 27 Nov, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

EXTRACT() function :

This function in MySQL is used to extract a part from a specified date.

Syntax :

EXTRACT(part FROM date)

Parameter :

This method accepts two parameters which are illustrated below:

  • part – Specified part to extract like SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR, etc.
  • date – Specified date to extract a part from.

Returns :

It returns the desired extracted part from a specified date.

Example-1 :

Extracting the week of the specified date “2020-11-24”.

SELECT EXTRACT(WEEK FROM "2020-11-24");

Output :

47

Example-2 :

Extracting hour from the specified date and time “2020-10-22 07:12:23”.

SELECT EXTRACT(HOUR FROM "2020-10-22 07:12:23");

Output :

7

Example-3 :

Extracting Year and month from the specified date and time “2020-10-22 07:12:23”.

SELECT EXTRACT(YEAR_MONTH FROM "2020-10-22 07:12:23");

Output :

202010

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads