When using SQL Server, you can use the T-SQL GETUTCDATE()
function to return the current UTC time (Coordinated Universal Time). UTC time is the primary time standard by which the world regulates clocks and time.
The return value of the GETUTCDATE()
function is derived from the computer on which the instance of SQL Server is running. The time zone is not included, and it is returned as a datetime value.
Syntax
The syntax goes like this:
GETUTCDATE()
So it doesn’t accept any arguments.
Example
Here’s an example of usage:
SELECT GETUTCDATE() AS Result;
Result:
+-------------------------+ | Result | |-------------------------| | 2018-06-17 05:17:46.750 | +-------------------------+
Formatting the Date
You can always use other T-SQL functions along with GETUTCDATE()
. For example, you can use the FORMAT()
function to format the date into the format you require (and have it returned as a string).
Example:
SELECT FORMAT(GETUTCDATE(), 'dddd, dd MMMM yyyy, hh:mm tt') AS Result;
Result:
+--------------------------------+ | Result | |--------------------------------| | Sunday, 17 June 2018, 05:43 AM | +--------------------------------+
Note that GETUTCDATE()
has less fractional seconds precision than the SYSUTCDATETIME()
function, which returns the UTC date/time as a datetime2
value, with a fractional seconds precision range from 1 to 7 digits.