CURRENT_TIMESTAMP2

Returns the current date and time of the system.

Note

This function has a special ANSI SQL form and can be called without parentheses.

Syntax

CURRENT_TIMESTAMP2() --> DATETIME2

CURRENT_TIMESTAMP2 --> DATETIME2

Arguments

None

Returns

The current system date and time, with type DATETIME2.

Notes

  • This function has a special ANSI SQL form and can be called without parentheses.

  • Aliases to this function include SYSDATE2 and GETDATE2.

  • To get the date only, see CURRENT_DATE.

Examples

Get the current system date and time

master=> SELECT CURRENT_TIMESTAMP2, CURRENT_TIMESTAMP2(), SYSDATE2, GETDATE2();
getdate0                             | getdate1                             | getdate2                             | getdate3
-------------------------------------+--------------------------------------+--------------------------------------+-------------------------------------
2019-12-07 23:04:26.300032671 +02:00 | 2019-12-07 23:04:26.300032671 +02:00 | 2019-12-07 23:04:26.300032671 +02:00 | 2019-12-07 23:04:26.300032671 +02:00

Find events that happen before this month

We will use TRUNC to get the date at the beginning of this month, and then filter.

master=> SELECT COUNT(*) FROM cool_dates WHERE dt <= TRUNC(CURRENT_TIMESTAMP2, month);
count
-----
 5