SQL Function to extract time from Datetime2

sql, sql-server

Solution

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

Problem

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'

Original source