HOURS Function [Date and Time]

Returns the number of hours since an arbitrary starting date and time, the number of whole hours between two specified times, or adds the specified integer-expression number of hours to a time.

Syntax

HOURSdatetime-expression
| datetime-expression, datetime-expression
| datetime-expression, integer-expression )

Parameters

Parameters

Parameter

Description

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 are subtracted from the date/time. If you supply an integer expression, the datetime-expression must be explicitly cast as a datetime data type.

Returns

INT

Examples

The following statement returns the value 17518758:

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

The following statement returns the value 4, to signify the difference between the two times:

SELECT HOURS( '1999-07-13 06:07:12',
	'1999-07-13 10:07:12' ) FROM iq_dummy

The following statement returns the datetime value 1999-05-13 02:05:07.000:

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

Usage

The second syntax returns the number of whole hours from the first date/time to the second date/time. The number might be negative.

Standards and Compatibility

  • SQL—Vendor extension to ISO/ANSI SQL grammar.

  • Sybase—Not supported by Adaptive Server Enterprise.

Related reference
CAST Function [Data Type Conversion]
CONVERT Function [Data Type Conversion]
MINUTES Function [Date and Time]
MONTHS Function [Date and Time]
REPLACE Function [String]
SECOND Function [Date and Time]
WEEKS Function [Date and Time]
YEAR Function [Date and Time]
YEARS Function [Date and Time]