FUNCTION REFERENCE
duration
Lengths of time in hours, minutes and seconds.
Lengths of time in hours, minutes and seconds.
Syntax
d = duration(H, MI, S)Syntax
d = duration(H, MI, S, MS)Syntax
d = duration(X)Syntax
d = duration(text, 'InputFormat', fmt)Syntax
d = duration(..., 'Format', fmt)Syntax
d = duration.emptyValues are stored as milliseconds; NaN is allowed. H, MI, S and MS combine
by implicit expansion; X is an n-by-3 matrix of [h m s] rows and gives a
column. Text without 'InputFormat' is 'hh:mm:ss' or 'dd:hh:mm:ss'. An
InputFormat reads only the digital forms; a unit letter ('h', 's', ...) or
any other letter is an error that names it, while text that does not fit
the format becomes NaN.
Formats: 'hh:mm:ss' (default), 'dd:hh:mm:ss', 'mm:ss', 'hh:mm', each of the
forms ending in seconds with '.S' to '.SSSSSSSSS', and 's', 'm', 'h', 'd',
'y' for one unit with a suffix (1.5 hr). Hours wider than two digits are
shown in full; a negative duration starts with a minus sign. Durations add
and subtract with durations, and a number beside a duration in + or - or in
concatenation counts as days of 24 hours, and so does a number compared
with a duration. They multiply and divide by numbers; duration ./ duration
is a number. double(d) is an error: use
seconds, minutes, hours or days. min, max, sum, mean and median take a
dimension, a vector of dimensions or 'all'; string(d) gives a missing
string for NaN.
Example
d = duration(1, 30, 0) % 01:30:00Example
d = duration(1, 30, 0) + 1 % 25:30:00Example
r = duration(3, 0, 0) ./ duration(1, 30, 0) % 2Example
d = duration('12:15:30.25', 'Format', 'hh:mm:ss.SS') % 12:15:30.25Example
d = [duration(1, 0, 0), 0.5] % 01:00:00 12:00:00Differences from MATLAB: Arrays are 2-D only; calendarDuration is not
supported yet. A duration range needs an explicit step.
These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.