SQL GETUTCDATE

The SQL Server GETUTCDATE function is a Date and Time Function used to return the current system timestamp as a DateTime value. The return value of the GETUTCDATE function is the current UTC (Coordinated Universal Time).

It is derived from the computer’s OS (Operating System) on which the Server instance runs. The syntax of the GETUTCDATE function is

GETUTCDATE()

SQL GETUTCDATE Function Example

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). Please refer to the list of SQL Date and time functions available on our Learn SQL Server page.

SELECT GETUTCDATE() AS [Current_Date]
Get Current Date 1

GETUTCDATE Example 2

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

Next, we used the SQL DATEPART to display the year value from today’s date & time. In the third one, we used the SQL DATENAME to display the Month name from today’s date & time.

In the last line, we used the DATEADD in SQL to display Tomorrow’s date & time.

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];
GETUTCDATE Example 2

SQL Server 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 SQL 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];

As you can see from the below, we used the DATEDIFF Date and Time to find the difference between the @dtime variable that we declared and the current date and time. Please refer to the SQL GETDATE and SQL CURRENT_TIMESTAMP functions.

GETUTCDATE Function 3
Categories SQL