GETDATE() Vs SYSDATETIME()
To get the current system date and time we can use GETDATE() or SYSDATETIME() function in SQL server.
The question is what the difference between them is.
To get the answer let execute the SQL statements mentioned bellow.
SELECT GETDATE() ‘GETDATE’, SYSDATETIME() ‘SYSDATETIME’
The output is mentioned bellow:
2012-05-14 18:05:04.720 2012-05-14 18:05:04.7232705
So exactly what the difference is?
When we use GETDATE() the precision is till milliseconds and in case of SYSDATETIME() the precision is till nanoseconds.
SYSDATETIME() is an important when using the data type DATETIME2.
The data type DATETIME2 stores dates and times in a higher precious than the (old) data type DATETIME and therefore the difference between GETDATE() and SYSDATETIME() is important when using DATETIME2.
So there is really no reason to keep on using GETDATE(). And therefore the simple advice is: in SQL Server 2008 always use SYSDATETIME() when you want to retrieve the current date and/or time.
Hope you like it.
Posted by: MR. JOYDEEP DAS