GetTheHour

HOW TO Get the Hour from a Date/Time
---Syntax---
SELECT dbo.GetTheHour(GETDATE())
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO
/*
   GetTheHour (Date To Character)
   Syntax: SELECT dbo.GetTheHour(GETDATE())
 */

CREATE FUNCTION [dbo].[GetTheHour] (@dtDateParam DateTime)
RETURNS int
AS
BEGIN
   DECLARE @TheHourIs int
   IF ISDATE(@dtDateParam)>0
      BEGIN           
        SELECT @TheHourIs = CAST(DATEPART(HOUR, @dtDateParam) as int)
      END
   ELSE
      BEGIN
SET @TheHourIs = 0
      END
   RETURN(@TheHourIs)
END
GO
 

Add Feedback