Sql-server – current_timestamp at time zone ‘UTC’ SQL Server equivalent

selectsql serversyntaxt-sqltimestamp

What is the equivalent of the Postgres "current_timestamp at time zone 'UTC'" in SQL Server?

How do I select the current timestamp in UTC in SQL Server?

Best Answer

What you're looking for is the SYSUTCDATETIME function, which is used like this:

SELECT SYSUTCDATETIME();

It returns the current system date and time, adjusted to UTC time.

This seems similar to what the postgres equivalent does (except it looks like current_timestamp includes timezone information, while SYSUTCDATETIME does not).

If you need the time zone information, you can use a similar construction in SQL Server with the SYSDATETIMEOFFSET function:

SELECT SYSDATETIMEOFFSET() AT TIME ZONE 'UTC';

The results look like this:

Screenshot of the results of calling the above-mentioned system functions, showing the results are the same with the exception that sysdatetimeoffset includes the time zone offset