Link to home
Start Free TrialLog in
Avatar of ktQueBIT
ktQueBIT

asked on

Extract time from datetime data type column

I have a database that has several datetime columns.  The thing is all I care about is the time portion of the column.  The thing is I need to retain the numeric time value as I will need to do time difference calculations on the remaining time values.  I know I cannot store this data in SQL as a datetime but I want to be able to display the time without on my reports without showing the bogus date used by SQL when you only load the time value in a datetime column.  Any guidance would be appreciated.  
Avatar of Aneesh
Aneesh
Flag of Canada image

SELECT convert(VARCHAR,GETDATE(),108)
If your datetime field is dt, then

select convert(datetime, convert(varchar, dt, 108)), other1, other2 from table1

will result in the time portion only remaining.

To do time different calculations between two datetimes

select dt1 - dt2 from table1

the resulting type is datetime
ASKER CERTIFIED SOLUTION
Avatar of PaultheBroker
PaultheBroker
Flag of Afghanistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial