0 Replies - 1560 Views - Last Post: 01 December 2008 - 09:12 PM

#1 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

MSSQL Uder Defined FUnction to remove the tine from a DATETIME value

Posted 01 December 2008 - 09:12 PM

Description: Pass the DATETIME value you wish converted an example will be providedThins is an invaluable UDF in MSSQL I created in SQL 2005 to remove the time part of a DATETIME datatype. Even is no time is passed SQL stored 0:00:000 to the end of the date
/* User Defied Function */
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		Richard L. McCutchen
-- Create date: 11JAN07
-- Description:	Function to return the time part of a DATETIME data type
-- =============================================
CREATEFUNCTION [dbo].[RemoveTimeFromDateTimeValue]  
(
	-- Add the parameters for the function here
	@input_string DATETIME
)
RETURNS DATETIME
AS
BEGIN
	RETURN (SELECT CAST(FLOOR(CAST(@input_string AS FLOAT)) AS DATETIME))
END

/* Example Usage */
--In this case we want the time part removed from the intrinsic GETDATE() Functon
SELECT dbo.ReoveTieFromDateTimeValue(GETDATE())



Is This A Good Question/Topic? 0
  • +

Page 1 of 1