Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Function to extract time from Datetime2

Tags:

sql

sql-server

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'

like image 680
littlechris Avatar asked Sep 03 '09 10:09

littlechris


1 Answers

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

like image 195
marc_s Avatar answered Sep 22 '22 20:09

marc_s