title: T-SQL change time part of a DateTime
body: <p>I have a stored procedure and I passing it a this parameters:</p>
  
  <p>Now how can I change the time part in the <code>@filterDateFrom</code> and <code>@filterDateTo</code> to set to <code>@filterTimeFrom</code>  and <code>@filterTimeTo</code> .</p>
  
  <p>here is the whole stored procedure</p>
  
  <pre><code>USE [DBName]
  GO
  /****** Object:  StoredProcedure [dbo].[AdminGetAdminBusinessLogList]    Script Date: 1/3/2014 12:17:53 PM ******/
  SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  
  ALTER PROCEDURE [dbo].[AdminGetAdminBusinessLogList]
  @UserContextUserId INT, 
  @UserContextCompanyId INT, 
  @UserContextSessionId UNIQUEIDENTIFIER, 
  @UserContextProcessId UNIQUEIDENTIFIER,
  @UserContextIPAddress NVARCHAR (100),
  @filterDateFrom DATETIME, 
  @filterDateTo DATETIME, 
  @filterAffectedCompanyId INT, 
  @filterUserId INT, 
  @FilterEventIdTableType FilterEventIdTableType READONLY, 
  @filterTableName NVARCHAR(100), 
  @filterEntityId INT,
  @filterTimeFrom INT,
  @filterTimeTo INT
  AS
  BEGIN
      SET NOCOUNT ON;
  
      BEGIN TRY
          EXEC CheckRights @UserContextUserId, NULL, @@PROCID
  
          DECLARE @MaxRowCount INT
          SELECT @MaxRowCount = CAST([Value] AS INT) FROM Configuration WHERE [Key] = 'System.Sql.MaxRowCount'
  
  
          DECLARE @EventIdTableTypeCount INT
          SET @EventIdTableTypeCount = (SELECT COUNT(*) FROM @FilterEventIdTableType)
  
          SET @filterDateFrom = CAST(FLOOR(CAST(@filterDateFrom AS FLOAT)) AS DATETIME);
          SET @filterDateFrom = DATEADD(hh, @filterTimeFrom, @filterDateFrom);
  
          SET @filterDateTo = CAST(FLOOR(CAST(@filterDateTo AS FLOAT)) AS DATETIME);
          SET @filterDateTo = DATEADD(hh, @filterTimeTo, @filterDateTo);
  
          CREATE TABLE #Temp
          (
              [Id] INT NOT NULL
              PRIMARY KEY (Id)                        
          )
  
          SET ROWCOUNT @MaxRowCount
  
          --Temp table
        IF (@filterTableName IS NULL OR @filterTableName = '')
          BEGIN
           INSERT INTO #Temp      
              SELECT
                  BusinessLog.Id
              FROM
                  dbo.BusinessLog  
              WHERE
                  (@filterDateFrom IS NULL OR EventDate &gt;= @filterDateFrom) AND 
                  (@filterDateTo IS NULL OR EventDate &lt; @filterDateTo) AND
                  (@filterAffectedCompanyId IS NULL OR (UserContextCompanyId = @filterAffectedCompanyId OR AffectedCompanyId = @filterAffectedCompanyId)) AND
                  (@filterUserId  IS NULL OR BusinessLog.UserContextUserId = @filterUserId) AND
                  (@UserContextIPAddress IS NULL OR UserContextIPAddress LIKE @UserContextIPAddress + '%') AND
                  (@EventIdTableTypeCount = 0 OR BusinessLog.EventId IN (SELECT Value FROM @FilterEventIdTableType))
          END
  
        ELSE
  
          BEGIN
           INSERT INTO #Temp      
              SELECT
                  BusinessLog.Id
              FROM
                  dbo.BusinessLog  
              INNER JOIN dbo.AuditLog ON AuditLog.BusinessLogId = BusinessLog.Id
              WHERE
                  (AuditLog.TableName = @filterTableName AND AuditLog.EntityId = @filterEntityId)
          END     
  
          --ROWCOUNT visszaállítása
          SET ROWCOUNT 0
  
          --BusinessLog       
          SELECT
              BusinessLog.Id, EventId, Audience, EventDate, UserContextUserId, UserAccount.UserFullName AS UserContextUserFullName,  UserContextCompanyId, cForUserContext.Name AS UserContextCompanyName, AffectedCompanyId, cForAffected.Name AS AffectedCompanyName, UserContextIPAddress, UserAccount.UserUniqueId AS UserContextUserUniqueId, BusinessLog.MessageFormatVersion
          FROM
              dbo.BusinessLog
          LEFT JOIN dbo.Company cForAffected ON cForAffected.Id = BusinessLog.AffectedCompanyId
          LEFT JOIN dbo.Company cForUserContext ON cForUserContext.Id = BusinessLog.UserContextCompanyId
          LEFT JOIN dbo.UserAccount ON UserAccount.Id = BusinessLog.UserContextUserId
          INNER JOIN #Temp ON #Temp.Id = BusinessLog.Id
  
          --BusinessLogParameter
          SELECT
              BusinessLogId, IsResource, Value
          FROM
              dbo.BusinessLogParameter
          INNER JOIN #Temp ON #Temp.Id = BusinessLogParameter.BusinessLogId
          ORDER BY #Temp.Id ASC
  
      END TRY
      BEGIN CATCH
          DECLARE @error NVARCHAR(100)
          DECLARE @severity INT
  
          SELECT @error = ERROR_MESSAGE()
          SELECT @severity = ERROR_SEVERITY()
  
          RAISERROR (@error, @severity, 1)
      END CATCH
  END
  </code></pre>
  
  <p>Thanks</p>