In this article we will look into the difference between GETDATE and SYSDATETIME functions.
The GETDATE() function uses datetime data type and returns the current date, time in the format "YYYY-MM-DD HH:MI:SS". Here's an example:
SELECT GETDATE() AS CurrentDateTime;
This will return the current date and time in the following format:
CurrentDateTime
-----------------------
2023-04-05 11:37:59.940
Similarly the SYSDATETIME() function uses datetime2 data type and returns the current date and time in the format "YYYY-MM-DD HH:MI:SS.mmmmmm".
Here's an example:
SELECT SYSDATETIME() AS CurrentDateTime;
This will return the current date and time in the following format:
CurrentDateTime
----------------------------
2023-04-05 11:37:59.9605381
Note : SYSDATETIME() function provides more precision than GETDATE() function by including the fractional seconds. Also, the precision of SYSDATETIME() function can be adjusted by specifying a precision parameter.