Geeks With Blogs
Robin Hames Hints, tricks and tips relating to MS SQL Server and .NET

Just some code to get the time part only from a DateTime field (is SQL Server 2000 or 2005), with the date set to a reference date


declare @timetest datetime

declare @refdate datetime


set @timetest = getdate()

set @refdate = '30 Dec 1899 00:00:00'


select @timetest

      , @refdate

      , dateadd(day, datediff(day, @refdate , @timetest), @refdate ) -- date part only

      , dateadd(day, datediff(day, @refdate , @timetest) * -1, @timetest) -- time part only, with reference date


Instead of @refdate, you could use 0.


Posted on Tuesday, August 11, 2009 12:24 PM SQL Server | Back to top

Comments on this post: Getting the Time part only from a SQL Server DateTime

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Rhames | Powered by: