Skip to main content

day_of_month

1. DAY_OF_MONTH Function

The DAY_OF_MONTH function in H2 database is used to extract the day of the month from a given date.

2. Syntax

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

DAY_OF_MONTH(date)

Arguments

  • date: The input date from which the day of the month needs to be extracted. It should be a valid date value.

Return

  • The DAY_OF_MONTH function returns an integer value representing the day of the month.

3. Notes

  • The DAY_OF_MONTH function in H2 database extracts the day component from the given date.
  • The input date should be in a valid date format recognized by H2 database, such as 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MI:SS'.
  • If the input date is NULL, the DAY_OF_MONTH function will return NULL.

4. Examples

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

Example 1 - Extracting the day of the month from a specific date:

SELECT DAY_OF_MONTH(DATE '2022-03-15') AS day;

Output:

day
---
15

Example 2 - Extracting the day of the month from a column of dates:

CREATE TABLE events (
id INT PRIMARY KEY,
event_date DATE
);

INSERT INTO events VALUES (1, DATE '2022-03-15'), (2, DATE '2022-04-20'), (3, DATE '2022-05-10');

SELECT id, event_date, DAY_OF_MONTH(event_date) AS day
FROM events;

Output:

id | event_date  | day
---+-------------+----
1 | 2022-03-15 | 15
2 | 2022-04-20 | 20
3 | 2022-05-10 | 10
  • month - Extract the month from a date
  • year - Extract the year from a date