MONTH
MONTH is a function in SQL used to extract the month from a specified date, returning an integer ranging from 1 to 12. The extracted month value corresponds to the 12 months of the year, with 1 for January and 12 for December.
MONTH(date)
- date: The “date” parameter represents the input date that needs to be evaluated in order to extract the month portion. This input date should adhere to the MySQL standard for dates (YYYY-MM-DD) or datetime (YYYY-MM-DD HH
Example
Output
Explanation
The MONTH() function in MySQL retrieves the month from the specified date. In this example, it extracts the month from the timestamp ‘2021-03-08’, resulting in the output ‘3’.
MONTH(date)
- date: This parameter represents the date value from which the month is to be extracted. It accepts a variety of formats, including date strings, date-type variables, or columns containing date data.
Example
Output
Explanation
In the example, the MONTH
function extracts the month from the date (‘2022-06-30’), and the result is 6.
MONTH(date)
- date: The input DATE or TIMESTAMP from which the month value is to be extracted. This function returns the month of the given date as a number. It ranges from 1 to 12 where 1 represents January and 12 represents December.
Example
Output
Explanation
In Oracle SQL, the MONTH
function extracts the month from the provided date. The above example returns the current month of the system’s date. In this case, ‘6’ represents June.