SQL Server SYSUTCDATETIME() Function
The SYSUTCDATETIME()
function in SQL Server is used to return the current system UTC date and time value. Unlike the SYSDATETIME()
function, it returns a date and time value with the UTC offset.
Syntax
SYSUTCDATETIME()
Use Cases
The SYSUTCDATETIME()
function is very useful in scenarios where the current UTC time needs to be obtained. It is often used to compare and calculate with other time values to ensure a consistent time standard across different time zones and geographical locations.
Examples
Here are two examples of using the SYSUTCDATETIME()
function to demonstrate how to obtain the current UTC date and time value:
Example 1
SELECT SYSUTCDATETIME() AS 'Current UTC Date Time';
Result:
Current UTC Date Time |
---|
2023-03-11 06:38:14.9898796 |
Example 2
SELECT 'Event occurred at: ' + CONVERT(VARCHAR(30), SYSUTCDATETIME()) AS 'Event Time (UTC)';
Result:
Event Time (UTC) |
---|
Event occurred at: 2023-03-11 06:39:48.3454597 |
Conclusion
The SYSUTCDATETIME()
function is a useful function for obtaining the current UTC date and time value in SQL Server. It ensures consistency in time standards when comparing and calculating time values, especially in operations involving different time zones and geographical locations.