Link to home
Start Free TrialLog in
Avatar of martgriff
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
Avatar of ptjcb
ptjcb
Flag of United States of America 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
SOLUTION
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
Avatar of martgriff
martgriff

ASKER

No i meant just storing the data in the column, but dont think you can store just the time.

Will have to pull either date or time out in the query instead.

Thanks
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