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

second

1. SECOND Function

======= second | H2 Function | SQLDoc

second

1. SECOND Function

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The SECOND function in H2 database is used to extract the seconds component from a given time or timestamp value.

2. Syntax

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

SECOND(time)

Arguments

  • time: The time or timestamp value from which the seconds component needs to be extracted. It should be a valid time or timestamp value.

Return

  • The SECOND function returns an integer representing the seconds component of the given time or timestamp value.

3. Notes

  • The SECOND function in H2 database extracts the seconds component from the time or timestamp value, ranging from 0 to 59.
  • If the input time or timestamp value is not valid or null, the SECOND function will return NULL.
  • Make sure to provide a valid time or timestamp value as the argument to the SECOND function to get accurate results.

4. Examples

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

Example 1 - Extracting seconds from a time value:

SELECT SECOND(TIME '13:45:27') AS seconds;

Output:

seconds
-------
27

Example 2 - Extracting seconds from a timestamp value stored in a column:

CREATE TABLE events (
id INT PRIMARY KEY,
event_time TIMESTAMP
);

INSERT INTO events VALUES (1, TIMESTAMP '2022-04-15 10:30:45'), (2, TIMESTAMP '2022-04-15 14:20:55');

SELECT id, event_time, SECOND(event_time) AS seconds
FROM events;

Output:

id |         event_time         | seconds
---+----------------------------+---------
1 | 2022-04-15 10:30:45.000000 | 45
2 | 2022-04-15 14:20:55.000000 | 55
  • minute - Extract minutes component
  • hour - Extract hours component