Functions for Obtaining the Current Time and Date
clock_timestamp()
Description: Returns the current timestamp of the real-time clock.
Return type: timestamp with time zone
Example:
1 2 3 4 5 |
SELECT clock_timestamp(); clock_timestamp ------------------------------- 2026-01-14 15:18:30.766999+08 (1 row) |
current_date
Description: Returns the current date.
Return type: date
Example:
1 2 3 4 5 |
SELECT current_date; date ------------ 2026-01-14 (1 row) |
curdate()
Description: Returns the current date. This function is compatible with MySQL. This parameter is supported only by clusters of version 8.2.0 or later.
Return type: date
Example:
1 2 3 4 5 |
SELECT curdate(); curdate ------------ 2026-01-14 (1 row) |
current_time
Description: Returns the current time.
Return type: time with time zone
Example:
1 2 3 4 5 |
SELECT current_time; timetz -------------------- 16:58:07.086215+08 (1 row) |
curtime([fsp])
Description: Returns the current time.
fsp is an optional parameter. It specifies a fractional seconds precision and its value is an integer. This parameter is supported only by clusters of version 8.2.0 or later.
Return type: time with time zone
Example:
1 2 3 4 5 6 7 8 9 10 |
SELECT curtime(); timetz -------------------- 16:58:07.086215+08 (1 row) SELECT curtime(2); timetz -------------------- 16:58:07.08+08 (1 row) |
current_timestamp
Description: Returns the current date and time (start time of the current transaction).
Return type: timestamp with time zone
Example:
1 2 3 4 5 |
SELECT current_timestamp; pg_systimestamp ------------------------------- 2026-01-14 15:30:51.717927+08 (1 row) |
localtime
Description: Returns the current time.
Return type: time
Example:
1 2 3 4 5 |
SELECT localtime; time ----------------- 15:40:54.885857 (1 row) |
localtimestamp
Description: Returns the current date and time.
Return type: timestamp
Example:
1 2 3 4 5 |
SELECT localtimestamp; timestamp ---------------------------- 2026-01-14 15:41:49.111089 (1 row) |
statement_timestamp()
Description: Returns the current date and time (start time of the current transaction).
Return type: timestamp with time zone
Example:
1 2 3 4 5 |
SELECT statement_timestamp(); statement_timestamp ------------------------------- 2026-01-14 15:43:14.907913+08 (1 row) |
sysdate
Description: Returns the current date and time of the system.
Return type: timestamp
Example:
1 2 3 4 5 |
SELECT sysdate; sysdate --------------------- 2026-01-14 15:47:58 (1 row) |
timeofday()
Description: Returns the current date and time (similar to clock_timestamp(), but the return value is of the text type).
Return type: text
Example:
1 2 3 4 5 |
SELECT timeofday(); timeofday ------------------------------------- Wed Jan 14 15:51:04.053480 2026 CST (1 row) |
transaction_timestamp()
Description: Returns the system date and time when the current transaction starts. It is equivalent to current_timestamp.
Return type: timestamp with time zone
Example:
1 2 3 4 5 6 |
SELECT transaction_timestamp(); transaction_timestamp ------------------------------- 2026-01-14 16:59:52.045873+08 (1 row) |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot