<<<<<<< HEAD monthname | H2 | SQLDoc
Skip to main content

monthname

1. MONTHNAME Function

======= monthname | H2 Function | SQLDoc

monthname

1. MONTHNAME Function

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The MONTHNAME function in H2 database is used to retrieve the name of the month for a given date.

2. Syntax

The syntax for the MONTHNAME function in H2 database is as follows:

MONTHNAME(date)

Arguments

  • date: The date value for which the month name needs to be retrieved. It should be a valid date value.

Return

  • The MONTHNAME function returns the name of the month corresponding to the given date as a string.

3. Notes

  • The MONTHNAME function in H2 database returns the full name of the month in English.
  • The input date should be in a valid date format. If the date is not valid or in an incorrect format, the MONTHNAME function will return NULL.
  • Ensure that the date is properly formatted and matches the expected format to avoid errors.

4. Examples

Here are a few examples demonstrating the usage of the MONTHNAME function in H2 database:

Example 1 - Retrieving the month name for a specific date:

SELECT MONTHNAME(DATE '2022-07-15') AS month_name;

Output:

month_name
-------------
July

Example 2 - Retrieving the month name for a date column:

CREATE TABLE orders (
id INT PRIMARY KEY,
order_date DATE
);

INSERT INTO orders VALUES (1, DATE '2022-04-05'), (2, DATE '2022-09-18'), (3, DATE '2022-12-01');

SELECT id, order_date, MONTHNAME(order_date) AS month_name
FROM orders;

Output:

id | order_date  | month_name
---+-------------+-------------
1 | 2022-04-05 | April
2 | 2022-09-18 | September
3 | 2022-12-01 | December
  • month - Retrieve the month component of a date
  • year - Retrieve the year component of a date