SQL GETUTCDATE Function

The SQL GETUTCDATE function is a SQL Date and Time Function used to return the current system timestamp as a DateTime value. The return value of this GETUTCDATE function is the current UTC time (Coordinated Universal Time). Which derived from the OS (Operating System) of the computer on which the SQL Server instance is running.

The syntax of the SQL Server GETUTCDATE is

GETUTCDATE()

SQL GETUTCDATE Function Example 1

The GETUTCDATE function returns the datetime data type, and the format is: ‘yyyy-mm-dd hh:mm:ss.mmm’ (you can see, fractional seconds precision is 3).

SELECT GETUTCDATE() AS [Current_Date]
SQL GETUTCDATE Function 1

GETUTCDATE Function Example 2

This function returns the current system timestamp. In this example, we are going to show you the GETUTCDATE function with examples.

SELECT 'Today' AS 'TODAY', GETUTCDATE() AS [Curr_Date];

SELECT 'Year' AS 'YEAR', DATEPART(year, GETUTCDATE()) AS [Present_Year]; 

SELECT 'Month' AS 'MONTH', DATENAME(month, GETUTCDATE()) AS [Month_Name]; 

SELECT 'Tomorrow' AS 'DAY', DATEADD(day, 1, GETUTCDATE()) AS [NextDay];
SQL GETUTCDATE Function 2

We used the SQL DATEPART function to display the year value from today’s date & time

SELECT 'Year' AS 'YEAR', DATEPART(year, GETUTCDATE()) AS [Present_Year];

Next, We used the SQL DATENAME function in SQL Server to display the Month name from today’s date & time

SELECT 'Month' AS 'MONTH', DATENAME(month, GETUTCDATE()) AS [Month_Name];

We used the SQL DATEADD function to display the Tomorrow date & time

SELECT 'Tomorrow' AS 'DAY', DATEADD(day, 1, GETUTCDATE()) AS [NextDay];

SQL GETUTCDATE Function Example 3

In this example, we are going to find the differences in Minutes, Seconds, and Milliseconds between the Current Date & time and a variable. For this, we are using the DATEDIFF function.

DECLARE @dtime DATETIME
SET @dtime = '2016-08-27 02:54:27.530'

SELECT 'Minutes_Difference' AS 'MINUTE', DATEDIFF(MINUTE, @dtime, GETUTCDATE()) AS [Number of Minutes];

SELECT 'Seconds_Difference' AS 'SECOND', DATEDIFF(SECOND, @dtime, GETUTCDATE()) AS [Number of Seconds];

SELECT 'Millisecond_Diff' AS 'MILLISECOND', DATEDIFF(MILLISECOND, @dtime, GETUTCDATE()) AS [Number of MilliSeconds];
SQL GETUTCDATE Function 3

As you can see from the above, we used the DATEDIFF Date and Time Function to find the difference between the @dtime variable that we declared and the current date and time.