martgriff
asked on
Just show time in datetime column sql server 2005
I have a datetime column in a table in sql server 2005, can i have just the time being displayed as currently it adds the date also?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can store the time portion only in a column by using one of the following formulas on a datetime value.
If you are storing a float value,
time_fl = cast(datetime_col as float) - cast(datetime_col as integer)
If you are storing a datetime value
time_dt = datetime_col - cast(datetime_col as integer)
select time_fl, time_dt
will return
.3450085185, 1900-01-01 08:16:55.360
You can use convert() to display the time appropriately.
Tom
If you are storing a float value,
time_fl = cast(datetime_col as float) - cast(datetime_col as integer)
If you are storing a datetime value
time_dt = datetime_col - cast(datetime_col as integer)
select time_fl, time_dt
will return
.3450085185, 1900-01-01 08:16:55.360
You can use convert() to display the time appropriately.
Tom
ASKER
Will have to pull either date or time out in the query instead.
Thanks