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

dayname

1. DAYNAME Function

======= dayname | H2 Function | SQLDoc

dayname

1. DAYNAME Function

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The DAYNAME function in H2 database is used to retrieve the name of the day of the week for a given date.

2. Syntax

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

DAYNAME(date)

Arguments

  • date: The date for which you want to retrieve the day name. It should be a valid date value.

Return

  • The DAYNAME function returns the name of the day of the week for the given date as a string.

3. Notes

  • The DAYNAME function in H2 database considers Monday as the first day of the week and Sunday as the last day of the week.
  • The input date should be in a valid date format recognized by H2 database.
  • If the input date is NULL, the DAYNAME function will return NULL.
  • Ensure that the date format is correct to avoid errors while using the DAYNAME function.

4. Examples

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

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

SELECT DAYNAME(DATE '2022-12-25') AS day_name;

Output:

day_name
--------
Sunday

Example 2 - Retrieving the day names for dates stored in a column:

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

INSERT INTO events VALUES (1, DATE '2022-01-01'), (2, DATE '2022-02-15'), (3, DATE '2022-03-27');

SELECT id, event_date, DAYNAME(event_date) AS day_name
FROM events;

Output:

id | event_date  | day_name
---+-------------+---------
1 | 2022-01-01 | Saturday
2 | 2022-02-15 | Tuesday
3 | 2022-03-27 | Sunday
  • DAYOFWEEK - Retrieve the numeric value of the day of the week for a given date.