Timestamp Functions
CURRENT_TIMESTAMP
Overview
The CURRENT_TIMESTAMP()
returns the current timestamp value representing the date and time the query was executed.
Note that the time returned by this function is the time when the query was executed.
Syntax
CURRENT_TIMESTAMP(precision)
The precision
is used to set the number of digits in the fractional seconds precision in the second field.
If you omit the precision
, the CURRENT_TIMESTAMP()
function will return a current timestamp that includes the complete fractional seconds precision.
The maximum precision value that you can input is 6.
Examples
#Case 1: Current timestamp
The following example shows how to get the current date and time with a CURRENT_TIMESTAMP()
function:
SELECT CURRENT_TIMESTAMP AS "Current Time";
The final result will display the current date and time in your timezone:
+-----------------------------+
| Current Time |
+-----------------------------+
| 2022-08-31 16:56:06.464016 |
+-----------------------------+
#Case 2: Current timestamp with precision
Let’s assume we want to get the current timestamp but with a 2-fractional seconds precision:
SELECT CURRENT_TIMESTAMP(2);
The function will return the current date and time with 2 digits after seconds:
+-------------------------+
| current_timestamp |
+-------------------------+
| 2022-08-31 17:15:22.16 |
+-------------------------+