Main Content

hour

Hour component of input date and time

Description

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.

example

Examples

collapse all

t = datetime('today'):hours(8):datetime('tomorrow');
t.Format = 'MMM dd, HH:mm'
t = 1x4 datetime
   Sep 05, 00:00   Sep 05, 08:00   Sep 05, 16:00   Sep 06, 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

| | |