In this article. When we are writing the SQL Queries based on date calculation, we need to play with date format based on client requirement, as we have default built in function such as GETDATE and GetUTCDate() to provide the server date and time.
- SYSDATETIME(): Returns a datetime2(7) value that contains the date and time of the computer on which the instance of SQL Server is running. (which is new to SQL Server 2008), The results will be the same unless the date format includes the nanosecond portion of the time. ( More Details >>Link )
- 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. ( More Details >>Link )
- GETUTCDATE(): Returns date and GMT time ( More Details >> Link )
- GETDATE(): Returns server date and time ( More Details >> Link)
SELECT SYSDATETIME() AS [SYSDATETIME()] ,SYSDATETIMEOFFSET() AS [SYSDATETIMEOFFSET()] ,SYSUTCDATETIME() AS [SYSUTCDATETIME()] ,CURRENT_TIMESTAMP AS [CURRENT_TIMESTAMP] ,GETDATE() AS [GETDATE()] ,GETUTCDATE() AS [GETUTCDATE()];
Here is the result set.
SYSDATETIME() 2007-04-30 13:10:02.0474381 SYSDATETIMEOFFSET()2007-04-30 13:10:02.0474381 -07:00 SYSUTCDATETIME() 2007-04-30 20:10:02.0474381 CURRENT_TIMESTAMP 2007-04-30 13:10:02.047 GETDATE() 2007-04-30 13:10:02.047 GETUTCDATE() 2007-04-30 20:10:02.047