Contents Index HOUR function [Date and time] HTTP_HEADER function [HTTP]

ASA SQL Reference
  SQL Functions
    Alphabetical list of functions

HOURS function [Date and time]


Function 

Given two timestamps, this function returns the integer number of hours between them. It is recommended that you use the DATEDIFF function [Date and time] instead for this purpose.

Given a single date, this function returns the number of hours since 0000-02-29 00:00:00.

Given one date and an integer, it adds the integer number of hours to the specified timestamp. It is recommended that you use the DATEADD function [Date and time] instead for this purpose.

Syntax 1 returns an integer. Syntax 2 returns a timestamp.

Syntax 1 

HOURS ( [ datetime-expression, ] datetime-expression )

Syntax 2 

HOURS ( datetime-expressioninteger-expression )

Parameters 

datetime-expression    A date and time.

integer-expression    The number of hours to be added to the datetime-expression. If integer-expression is negative, the appropriate number of hours is subtracted from the datetime. If you supply an integer expression, the datetime-expression must be explicitly cast as a datetime data type.

For information on casting data types, see CAST function [Data type conversion].

Standards and compatibility 
Example 

The following statements return the value 4, signifying that the second timestamp is four hours after the first. It is recommended that you use the second example (DATEDIFF).

SELECT HOURS( '1999-07-13 06:07:12',
   '1999-07-13 10:07:12' )
SELECT DATEDIFF( hour,
   '1999-07-13 06:07:12',
   '1999-07-13 10:07:12' )

The following statement returns the value 17 517 342.

SELECT HOURS( '1998-07-13 06:07:12' )

The following statements return the datetime 1999-05-13 02:05:07.0. It is recommended that you use the second example (DATEADD).

SELECT HOURS(
   CAST( '1999-05-12 21:05:07' AS DATETIME ), 5)
SELECT DATEADD( hour, 5, '1999-05-12 21:05:07' )

Contents Index HOUR function [Date and time] HTTP_HEADER function [HTTP]