A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/sql/extract-function-in-mysql/ below:

EXTRACT() Function in MySQL - GeeksforGeeks

EXTRACT() Function in MySQL

Last Updated : 23 Jul, 2025

The EXTRACT() function in MySQL is a versatile tool used for retrieving specific components of date Whether we need the year, month, day or even the hour or minute.

This function simplifies date manipulation and makes queries involving date and time data more efficient and easier to understand. In this article, We will learn about the EXTRACT() Function in MySQL by understanding various examples.

EXTRACT() Function in MySQL

Syntax:

EXTRACT(unit FROM date)

Parameter:

This method accepts two parameters which are illustrated below:

Returns:

It returns the desired extracted part from a specified date.

Examples of EXTRACT() Function in MySQL Example 1: Extracting the Year

To extract the year from a date:

SELECT EXTRACT(YEAR FROM '2024-09-10') AS Year;

Output:

2024
Example 2: Extracting the Month

To extract the month from a date:

SELECT EXTRACT(MONTH FROM '2024-09-10') AS Month;

Output:

9
Example 3: Extracting the Day

To extract the day from a date:

SELECT EXTRACT(DAY FROM '2024-09-10') AS Day;

Output:

10
Example 4: Extracting the Hour

If you have a DATETIME or TIMESTAMP value, you can extract the hour:

SELECT EXTRACT(HOUR FROM '2024-09-10 15:30:00') AS Hour;

Output:

15
Advantages of the EXTRACT() Function in MySQL 1. Simplifies Date/Time Manipulation: 2. Improves Query Readability: 3. Efficient Data Filtering: 4. Supports Various Date/Time Units: 5. Works with Multiple Data Types Conclusion

The EXTRACT() function in MySQL simplifies the process of retrieving specific parts of a date or time value, making it easier to work with date-related data in queries. It's useful for operations like filtering, grouping, or formatting date values in reports and analyses.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4