UTC_TIMESTAMP
UTC_TIMESTAMP is a function in SQL that returns the current UTC date and time as a value in 'YYYY-MM-DD HH:MM:SS' or YYYYMMDDHHMMSS.uuuuuu format, depending on whether the function is used in a string or numeric context.
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
Output
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()
Example
Output
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()
Example
Output
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
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
Output
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.