SQL MONTH
The SQL MONTH function is used to extract the month from a given date. This function is useful when analyzing data based on months, filtering records by specific months, or performing date-related calculations in SQL queries.
In this tutorial, we will cover the syntax of the MONTH function, how it works, and step-by-step examples to demonstrate its usage.
Syntax of SQL MONTH Function
The basic syntax of the MONTH function is:
</>
Copy
SELECT MONTH(date_column)
FROM table_name;
Explanation:
MONTH(date_column): Extracts the month as a number (1-12) from the given date.FROM table_name: Specifies the table from which the data is retrieved.
You can also use the function directly with a static date:
</>
Copy
SELECT MONTH('2024-05-15') AS month_value;
This query returns 5, as the given date falls in May.
