days
Duration in fixed 24-hour days, or a duration converted to a number of days.
Category: Language Fundamentals > Data Types
Syntax
d = days(x)
Creates a duration of x days from a number.
n = days(d)
Converts the duration d to a number of days.
Description
A numeric input is turned into a duration whose display format is days; it can be added to datetimes and to other durations: days(2) + hours(3) is 2.125 days. A duration input goes the other way and returns a plain number, so days(duration(36,0,0)) is 1.5.
A day here always has 24 hours. For a step that follows the calendar, including daylight-saving changes, use caldays. Differences between datetimes are durations, so days(t2 - t1) is the elapsed number of days.
Input arguments
x- Numeric array.
d- duration array.
Output arguments
d- duration array in days, displayed as
1 day,2.5 days. n- Double array with the number of days.
Example
Both directions
days([1 2.5])
days(2) + hours(3)
t1 = datetime(2020,1,1);
t2 = datetime(2020,1,10);
days(t2 - t1)
Output
ans = 1×2 duration array
1 day 2.5 days
ans = duration
2.125 days
ans = 9