To return only the date portion of a DateTime variable in Microsoft SQL server, you need to use a combination of the dateadd and datediff functions in Transact-SQL.
-- Returns @DateTime at midnight; i.e., it removes the time portion of a DateTime value. CREATE function [dbo].[sudf_Common_DateOnly] ( @dtDateTime DateTime ) returns datetime as begin -- Get the date only return dateadd(dd, 0, datediff(dd, 0, @dtDateTime)) end
4 thoughts on “MS SQL: Get the Date portion from a DateTime”