tags:

views:

80

answers:

2

Is there a function to extract a timespan field from a datetime2 field?

e.g

datetime2 has '01/01/2009 12:30:00'

i want '12:30:00'

+3  A: 

Either just use the CAST function:

SELECT CAST(@datetime2var AS TIME)

or assign your "datetime2" variable to another variable of type "TIME":

DECLARE @timeVal TIME 

SET @timeVal = @datetime2var

SELECT @timeVal

Marc

marc_s
A: 

You will need something like

select convert(varchar(10), sysdate, 108)

The complete list of Date Time Functions is here : link text

Vaibhav
hey....why the downvote? whats my crime?
Vaibhav
I didn't downvote because I'm not sure, but sysdate doesn't work with SQL-Server 2005. I believe it is an oracle command. Use GetDate().
Jeff O