DateAndTime.Hour(DateTime) Method

Definition

Returns an integer value from 0 through 23 representing the hour of the day.

C#
public static int Hour(DateTime TimeValue);

Parameters

TimeValue
DateTime

Required. A Date value from which you want to extract the hour.

Returns

An integer value from 0 through 23 representing the hour of the day.

Examples

This example uses the Hour function to obtain the hour from a specified time. In the development environment, the time literal is displayed in short time format using the locale settings of your code.

VB
Dim someTime As Date
Dim someHour As Integer
someTime = #4:35:17 PM#
someHour = Hour(someTime)
' someHour now contains 16.

Remarks

You can also obtain the hour of the day by calling DatePart and specifying DateInterval.Hour for the Interval argument.

Applies to

Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also