hour

Hour of the day of a datetime.

Category: Language Fundamentals > Data Types

Syntax

h = hour(t)

Returns the hour component, 0 to 23.

Description

hour extracts just the hour on a 24-hour clock. Minutes and seconds are ignored, and the value is not rounded. To get the hour count of a duration, use hours instead.

Input arguments

t
datetime array.

Output arguments

h
Numeric array of the same size as t.

Example

Hours of several times

hour(datetime(2024, 1, 1, [0 13 23], 5, 0))
hour(datetime(2024, 1, 1, 13, 45, 0))
Output
ans = 1×3

     0    13    23
ans = 13

See also

minute second hms hours datetime