Main Content

hour

Hour component of input date and time

Description

example

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.

Examples

collapse all

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

| | |