Search content within the blog

Thursday, December 4, 2008

Sql Function that returns only datepart of SQL DateTime

create function DateOnly(@DateTime DateTime)
-- Returns @DateTime at midnight; i.e., it removes the time portion
--of a DateTime value.
returns datetime
as
begin
return dateadd(dd,0, datediff(dd,0,@DateTime))
end
go

Select dbo.DateOnly(getdate()) AS DateWithoutTime

No comments:

Post a Comment