You had to use DATEDIFF(MICROSECOND, @starttime, @endtime) to get the elapsed time in milliseconds, so your request should be changed to something like this:
DECLARE @starttime datetime DECLARE @endtime datetime SET @starttime =getdate() -- execute my query here SET @endtime = GETDATE() SELECT DATEDIFF(MICROSECOND, @starttime, @endtime)
Although you can use the built-in function called Include Client Statistics , which was explained here .
source share