Categories:

Context Functions (General)

CURRENT_TIMESTAMP¶

Returns the current timestamp for the system in the local time zone.

Aliases:

LOCALTIMESTAMP , GETDATE , SYSTIMESTAMP

Syntax¶

CURRENT_TIMESTAMP( [ <fract_sec_precision> ] )

CURRENT_TIMESTAMP
Copy

Arguments¶

fract_sec_precision

This optional argument indicates the precision with which to report the time. For example, a value of 3 says to use 3 digits after the decimal point (i.e. to specify the time with a precision of milliseconds).

The default precision is 9 (nanoseconds).

Valid values range from 0 - 9. However, most platforms do not support true nanosecond precision; the precision that you get might be less than the precision you specify. In practice, precision is usually approximately milliseconds (3 digits) at most.

Note

Fractional seconds are only displayed if they have been explicitly set in the TIMESTAMP_OUTPUT_FORMAT parameter for the session (e.g. 'YYYY-MM-DD HH24:MI:SS.FF').

Returns¶

Returns the current system time. The data type of the returned value is TIMESTAMP_LTZ.

Usage Notes¶

  • The setting of the TIMEZONE parameter affects the return value. The returned timestamp is in the time zone for the session.

  • The setting of the TIMESTAMP_TYPE_MAPPING parameter affects the return value. The returned timestamp is in the timestamp type for the session.

  • Do not use the returned value for precise time ordering between concurrent queries (processed by the same virtual warehouse) because the queries might be serviced by different compute resources (in the warehouse).

  • To comply with ANSI standards, this function can be called without parentheses.

  • The aliases SYSTIMESTAMP and GETDATE differ from CURRENT_TIMESTAMP in the following ways:

    • They do not support the fract_sec_precision argument.

    • These functions must be called with parentheses.

Examples¶

Set the time output format to YYYY-MM-DD HH24:MI:SS.FF:

ALTER SESSION SET TIMESTAMP_OUTPUT_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF';
Copy

Return the current timestamp with fractional seconds precision set to 2:

SELECT CURRENT_TIMESTAMP(2);
Copy
+------------------------+
| CURRENT_TIMESTAMP(2)   |
|------------------------|
| 2017-04-26 22:37:22.83 |
+------------------------+

Return the current timestamp with fractional seconds precision set to 4:

SELECT CURRENT_TIMESTAMP(4);
Copy
+--------------------------+
| CURRENT_TIMESTAMP(4)     |
|--------------------------|
| 2017-04-26 22:37:25.3530 |
+--------------------------+

Return the current timestamp with fractional seconds precision set to the default (9):

SELECT CURRENT_TIMESTAMP;
Copy
+-------------------------------+
| CURRENT_TIMESTAMP             |
|-------------------------------|
| 2017-04-26 22:37:28.188000000 |
+-------------------------------+