Main Content


Hour component of input date and time



h = hour(t) returns the hour component for each date and time specified in t.

The h output is a double array and contains integer values from 0 to 23. To assign values to the hour component of values in t, use t.Hour and modify the Hour property.


collapse all

t = datetime('today'):hours(8):datetime('tomorrow');
t.Format = 'MMM dd, HH:mm'
t = 1x4 datetime
   Feb 13, 00:00   Feb 13, 08:00   Feb 13, 16:00   Feb 14, 00:00

h = hour(t)
h = 1×4

     0     8    16     0

Input Arguments

collapse all

Input date and time, specified as a datetime array.

To support existing code that previously required Financial Toolbox™, hour also accepts serial date numbers and text as inputs, but they are not recommended. For more information, see Version History.

Extended Capabilities

Version History

Introduced in R2014b

expand all

See Also

| | |