Obtaining the Current Time

As we all know, SQL Server 2008 comes with a time data type. Obviously, as the name itself denotes, this data type is capable of storing the time sans the date component. So, how would one populate a time field or variable with the current system time?

One would think of using the getdate() function and do some manipulations on it using some more functions to pull out the time component out of it. At least, that is what I thought.

But, the answer is much more simpler:

1 DECLARE @CurrentTime time 2  SET @CurrentTime = GETDATE() 3 SELECT @CurrentTime
Time Data Type Results