Technical Article

Time to Execute a script


This script can be divided into two parts one at the beginning of the script and the other at the end of a script. It parses the getdate() and runs datediff to give you an easy to read info on the time taken to execute a script. It is easy to get this info from status bar, but it is not logged into the .rpt file.

--This part goes before your restore statement.
declare @starttime datetime
declare @endtime datetime
--declare @db varchar(20)
--declare @server varchar(20)

set @starttime=getdate()
--set @server = select @@servername

Print @starttime
--The above part goes before your script.
--This part is for your script.


--This part goes after your restore statement.
set @endtime= getdate()

print @endtime

print   'It took ' +
cast(datediff(hh,@starttime,@endtime) as varchar(20))+ 
'-Hours '+cast(datediff(mi,@starttime,@endtime) as varchar(20))+
'-Minutes and '+cast(datediff(ss,@starttime,@endtime) as varchar(20))+
'-Seconds to complete the Restore on the server ' +