September 25, 2020 at 3:48 pm
As to the actual code, a more straightforward way is to CAST to date, which will perforce remove the time value, then CAST back to datetime (this probably isn't strictly needed, but it aids in clarity
/*you want to be sure these settings are on before creating any object in SQL Server*/
SET ANSI_NULLS ON;
SET QUOTED_IDENTIFIER ON;
GO
CREATE FUNCTION DBO.TFNGETDATEONLY ( @InDate DATETIME )
RETURNS DATETIME
BEGIN
RETURN CAST(CAST(@InDate AS date) AS DATETIME) /*strip time/force time to midnight*/
/*end of function*/
END
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
Viewing post 16 (of 15 total)
You must be logged in to reply to this topic. Login to reply