current_timestamp
1. CURRENT_TIMESTAMP Function
=======current_timestamp
1. CURRENT_TIMESTAMP Function
>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62beThe CURRENT_TIMESTAMP function in H2 database is used to retrieve the current date and time.
2. Syntax
The syntax for the CURRENT_TIMESTAMP function in H2 database is as follows:
CURRENT_TIMESTAMP
Arguments
- None
Return
- The CURRENT_TIMESTAMP function returns the current date and time as a TIMESTAMP value.
3. Notes
- The CURRENT_TIMESTAMP function does not accept any arguments.
- The returned value is in the TIMESTAMP format, which includes both the date and the time.
- The current date and time are based on the system clock of the database server.
4. Examples
Here are a few examples demonstrating the usage of the CURRENT_TIMESTAMP function in H2 database:
Example 1 - Retrieving the current timestamp:
SELECT CURRENT_TIMESTAMP AS current_time;
Output:
current_time
--------------------
2022-01-01 10:30:45
Example 2 - Using the current timestamp in queries:
CREATE TABLE events (
id INT PRIMARY KEY,
event_name VARCHAR(100),
event_date TIMESTAMP
);
INSERT INTO events VALUES (1, 'Event 1', CURRENT_TIMESTAMP);
INSERT INTO events VALUES (2, 'Event 2', CURRENT_TIMESTAMP);
INSERT INTO events VALUES (3, 'Event 3', CURRENT_TIMESTAMP);
SELECT * FROM events;
Output:
id | event_name | event_date
---+------------+------------------------
1 | Event 1 | 2022-01-01 10:30:45.123
2 | Event 2 | 2022-01-01 10:30:45.123
3 | Event 3 | 2022-01-01 10:30:45.123
5. Related Functions
- current_date - Retrieve the current date
- current_time - Retrieve the current time