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

iso_year

1. ISO_YEAR Function

======= iso_year | H2 Function | SQLDoc

iso_year

1. ISO_YEAR Function

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The ISO_YEAR function in H2 database is used to extract the year from a given date or timestamp value according to the ISO 8601 standard.

2. Syntax

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

ISO_YEAR(date)

Arguments

  • date: The date or timestamp value from which the year needs to be extracted. It should be a valid date or timestamp value.

Return

  • The ISO_YEAR function returns the year as an integer value.

3. Notes

  • The ISO_YEAR function in H2 database follows the ISO 8601 standard for extracting the year from a date or timestamp.
  • The input date or timestamp should be in a valid format recognized by H2 database.
  • If the input date or timestamp is not a valid value or in an unrecognized format, the ISO_YEAR function will return NULL.
  • Ensure that the date or timestamp format used is compatible with H2 database to avoid errors.

4. Examples

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

Example 1 - Extracting the year from a date:

SELECT ISO_YEAR(DATE '2022-01-15') AS year;

Output:

year
----
2022

Example 2 - Extracting the year from a timestamp:

SELECT ISO_YEAR(TIMESTAMP '2022-02-28 14:30:00') AS year;

Output:

year
----
2022

Example 3 - Extracting the year from a column:

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

INSERT INTO events VALUES (1, DATE '2022-01-01'), (2, DATE '2022-06-15'), (3, DATE '2023-03-10');

SELECT id, event_date, ISO_YEAR(event_date) AS year
FROM events;

Output:

id | event_date  | year
---+-------------+------
1 | 2022-01-01 | 2022
2 | 2022-06-15 | 2022
3 | 2023-03-10 | 2023
  • iso_week - Extract the ISO week number from a date or timestamp
  • iso_day_of_week - Extract the ISO day of the week from a date or timestamp