The MONTHNAME() function in MySQL is used to return the full name of the month from a given date. This function takes a date or datetime expression as an argument and returns the name of the month in English (or the default language set for the MySQL server).
Syntax:
MONTHNAME(date)
- date: The date or datetime expression from which you want to extract the month name.
Example Usage:
-
Basic Example:
SELECT MONTHNAME('2024-12-23');Output:
December -
Using with a column in a table: Suppose you have a table
orderswith aorder_datecolumn of typeDATE, and you want to get the month names for all orders:SELECT order_id, MONTHNAME(order_date) AS month_name FROM orders; -
With the
CURDATE()function: You can also use theMONTHNAME()function withCURDATE()to get the current month's name:SELECT MONTHNAME(CURDATE());Output: It would return the current month's name, e.g.,
Decemberif run in December.
Notes:
- The result is returned as a string representing the full name of the month, e.g., "January", "February", etc.
- The output will be in the language set for the MySQL server. By default, it is in English unless the language is changed.
No comments:
Post a Comment