Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Convert DateTime to Time Only

Author  Topic 

chipembele
Posting Yak Master

106 Posts

Posted - 2010-06-25 : 05:10:14
Hi
We've got a field that is causing problems, It's a date time field that looks something like this 30/12/1899 18:00. Can someone advise how I can return just the time in my query results please?

Likewise we also have a Date filed thats returning the same. Ideally i'd like to just return the date for this one.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-06-25 : 05:13:09
If you are using SQL 2008, just convert it to time datatype

for 2000 / 2005

to get the date only
select dateadd(day, datediff(day, 0, datetimecol), 0)


to get the time only
select datetimecol - dateadd(day, datediff(day, 0, datetimecol), 0)



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

chipembele
Posting Yak Master

106 Posts

Posted - 2010-06-25 : 05:30:01
Thankyou
Go to Top of Page
   

- Advertisement -