UTC_TIMESTAMP
UTC_TIMESTAMP([fractional_seconds_precision])
Section titled “UTC_TIMESTAMP([fractional_seconds_precision])”- fractional_seconds_precision: This parameter determines the number of digits in the fractional part of the SECOND. The value for the parameter can range between 0 and 6, where the default is 0 when it’s not specified. It specifies the microseconds precision to be used in the generated timestamp.
Example
Section titled “Example”SELECT UTC_TIMESTAMP();Output
Section titled “Output”+---------------------+| UTC_TIMESTAMP() |+---------------------+| 2022-01-01 12:30:30 |+---------------------+Explanation
Section titled “Explanation”The UTC_TIMESTAMP() function returns the current UTC date and time as a value in ‘YYYY-MM-DD HH:MM:SS’ or YYYYMMDDHHMMSS format, depending on whether the function is used in a string or numeric context.
UTC_TIMESTAMP()
Section titled “UTC_TIMESTAMP()”Example
Section titled “Example”SELECT NOW() AT TIME ZONE 'utc';Output
Section titled “Output”2022-03-17 07:32:30.78978+00Explanation
Section titled “Explanation”In PostgreSQL, the function NOW() AT TIME ZONE 'utc' is used to get the current timestamp in UTC. It returns the current date and time in UTC.
UTC_TIMESTAMP is not available in SQL Server. Instead, SQL Server uses GETUTCDATE() to return the current database system timestamp as a datetime value. The equivalent syntax in SQL Server is:GETUTCDATE()
Section titled “UTC_TIMESTAMP is not available in SQL Server. Instead, SQL Server uses GETUTCDATE() to return the current database system timestamp as a datetime value. The equivalent syntax in SQL Server is:GETUTCDATE()”Example
Section titled “Example”SELECT GETUTCDATE() AS UTC_TIMESTAMP;Output
Section titled “Output”UTC_TIMESTAMP-----------------------2022-07-14 14:07:21.393Explanation
Section titled “Explanation”In SQL Server, the GETUTCDATE() function returns the current UTC date and time as a datetime value. The returned datetime value is in ‘yyyy-mm-dd hh:mi:ss.mmm’ format.
The example demonstrates how to use this function. The current UTC datetime is selected and returned with the column name ‘UTC_TIMESTAMP’.
UTC_TIMESTAMP() RETURNS TIMESTAMP
Section titled “UTC_TIMESTAMP() RETURNS TIMESTAMP”Oracle SQL does not have a built-in UTC_TIMESTAMP function, but you can use the combination of SYSTIMESTAMP and AT TIME ZONE to get the UTC timestamp. Here are the details.
Example
Section titled “Example”SELECT SYSTIMESTAMP AT TIME ZONE 'UTC' AS UTC_TIMESTAMP FROM dual;Output
Section titled “Output”UTC_TIMESTAMP-----------------------------01-AUG-21 10.10.11.123000000 UTCExplanation
Section titled “Explanation”The SYSTIMESTAMP AT TIME ZONE 'UTC' statement retrieves the current system timestamp and converts it into the UTC timezone. The FROM dual is necessary for SELECT statements that do not rely on a table to retrieve information.