Return System Date and Time values
Overview
The return system date and time value functions covered in this section are:
GETDATE
GETDATE
returns the current database system timestamp as a datetime value without the database time zone offset. This value is derived from the operating system of the computer on which the instance of SQL Server is running.
Return Type
datetime
Syntax
SELECT GETDATE()
GETUTCDATE
GETUTCDATE
Returns the current database system timestamp as a datetime value. The database time zone offset is not included. This value represents the current UTC time (Coordinated Universal Time). This value is derived from the operating system of the computer on which the instance of SQL Server is running.
Return Type
datetime
Syntax
SELECT GETUTCDATE()
SYSDATETIME
SYSDATETIME
returns a datetime2(7) value that contains the date and time of the computer on which the instance of SQL Server is running.
Syntax
SYSDATETIME ( )
Return Types
datetime2(7)
Example 1
The below example returns the current System Date and Time.
SELECT
SYSDATETIME(),
SYSDATETIMEOFFSET(),
SYSUTCDATETIME(),
GETDATE(),
GETUTCDATE()
/*
Returned:
SYSDATETIME() 2020-04-30 13:10:02.0474381
SYSDATETIMEOFFSET() 2020-04-30 13:10:02.0474381 -07:00
SYSUTCDATETIME() 2020-04-30 20:10:02.0474381
GETDATE() 2020-04-30 13:10:02.047
GETUTCDATE() 2020-04-30 20:10:02.047
*/
Example 2
The below example returns the current System Date.
SELECT
CONVERT(date, SYSDATETIME()),
CONVERT(date, SYSDATETIMEOFFSET()),
CONVERT(date, SYSUTCDATETIME()),
CONVERT(date, GETDATE()),
CONVERT(date, GETUTCDATE())
/* All returned 2020-04-30 */
Example 3
The below example returns the current System Time.
SELECT
CONVERT(time, SYSDATETIME()),
CONVERT(time, SYSDATETIMEOFFSET()),
CONVERT(time, SYSUTCDATETIME()),
CONVERT(time, GETDATE()),
CONVERT(time, GETUTCDATE())
/*
Returned:
SYSDATETIME() 13:18:45.3490361
SYSDATETIMEOFFSET() 13:18:45.3490361
SYSUTCDATETIME() 20:18:45.3490361
GETDATE() 13:18:45.3470000
GETUTCDATE() 20:18:45.3470000
*/
SYSDATETIMEOFFSET
SYSDATETIMEOFFSET
returns a datetimeoffset(7) value that contains the date and time of the computer on which the instance of SQL Server is running. The time zone offset is included.
Syntax
SYSDATETIMEOFFSET()
Return Types
datetimeoffset(7)
Example 1
The below example shows the formats returned by the Date and Time Functions
SELECT
SYSDATETIME() AS [SYSDATETIME()],
SYSDATETIMEOFFSET() AS [SYSDATETIMEOFFSET()],
SYSUTCDATETIME() AS [SYSUTCDATETIME()],
GETDATE() AS [GETDATE()],
GETUTCDATE() AS [GETUTCDATE()]
Example 2
The below example converts Date and Time to Date
SELECT
CONVERT(date, SYSDATETIME()),
CONVERT(date, SYSDATETIMEOFFSET()),
CONVERT(date, SYSUTCDATETIME()),
CONVERT(date, GETDATE()),
CONVERT(date, GETUTCDATE())
SYSUTCDATETIME
SYSUTCDATETIME
returns a datetime2 value that contains the date and time of the computer on which the instance of SQL Server is running. The date and time are returned as UTC time (Coordinated Universal Time). The fractional second precision specification has a range from 1 to 7 digits. The default precision is 7 digits.
Syntax
SYSUTCDATETIME()
Return types
datetime2
Example 1
SELECT
SYSDATETIME() AS [SYSDATETIME()],
SYSDATETIMEOFFSET() AS [SYSDATETIMEOFFSET()],
SYSUTCDATETIME() AS [SYSUTCDATETIME()],
GETDATE() AS [GETDATE()],
GETUTCDATE() AS [GETUTCDATE()]
Example 2
SELECT
CONVERT(date, SYSDATETIME()),
CONVERT(date, SYSDATETIMEOFFSET()),
CONVERT(date, SYSUTCDATETIME()),
CONVERT(date, GETDATE()),
CONVERT(date, GETUTCDATE())