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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s