Open In App

EXTRACT() Function in MySQL

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:

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
Article Tags :
SQL