Here is my best answer to the original question:
Try the following:
CREATE FUNCTION FloorDate(@dt datetime) RETURNS datetime WITH SCHEMABINDING AS BEGIN RETURN CONVERT(datetime, FLOOR(CONVERT(float, @dt))) END GO
To test, try the following. Note the use of "PERSISTED" for the computed column and the use of [dbo.] When calling a function
/*create a test table */ CREATE TABLE [dbo].[TableTestFloorDate]( [Id] [int] IDENTITY(1,1) NOT NULL, [TestDate] [datetime] NOT NULL, [TestFloorDate] AS ([dbo].[FloorDate]([TestDate])) PERSISTED, CONSTRAINT [PK_TableTestFloorDate] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) )
Now you can add an index to the calculated column (but see later)
CREATE INDEX IX_TestFloorDate ON [dbo].[TableTestFloorDate](TestFloorDate)
Insert some random data as many times as you want, but more (1000+) is better if you want to check index usage / execution plans
INSERT INTO TableTestFloorDate (TestDate) VALUES( convert(datetime, RAND()*50000))
Get Results
SELECT * FROM TableTestFloorDate WHERE TestFloorDate='2013-2-2'
Now here is GOTCHA ... The index created in the computed column is not used! Instead, even when selecting data in the TestFloorDate field to be saved, SQLServer (or at least my version) prefers the TestDate index.
CREATE INDEX IX_TestFloorDate ON [dbo].[TableTestFloorDate](TestDate)
I'm sure (from memory) that indexes on computed, persistent columns have an advantage in terms of performance - I think you just need to try / test your own specific actions
(Hope I helped!)