daysact

Actual number of days between dates

Description

example

NumDays = daysact(StartDate) returns the actual number of days between the MATLAB® base date and StartDate. In MATLAB, the base date 1 is 1-Jan-0000 A.D. See datenum for a similar function.

example

NumDays = daysact(___,EndDate) returns the actual number of days between StartDate and the optional argument EndDate.

If EndDate is earlier than StartDate, NumDays is negative. Under this convention, all months contain 30 days.

Either input argument can contain multiple values, but if so, the other must contain the same number of values or a single value that applies to all. For example, if StartDate is an n-row character array of date character vectors, then EndDate must be an N-by-1 vector of integers or a single integer. NumDays is then an N-by-1 vector of date numbers.

Examples

collapse all

Determine the NumDays using date character vectors for StartDate and EndDate.

NumDays = daysact('7-sep-2002',  '25-dec-2002')
NumDays = 109

Determine the NumDays using a datetime array for StartDate.

NumDays = daysact(datetime('7-sep-2002','Locale','en_US'),  '25-dec-2002')
NumDays = 109

Determine the NumDays using a vector for EndDate.

MoreDays = ['09/07/2002'; '10/22/2002'; '11/05/2002'];
NumDays = daysact(MoreDays, '12/25/2002')
NumDays = 3×1

109
64
50

Input Arguments

collapse all

Start date, specified as a scalar or an N-by-1 or 1-by-N vector using serial date numbers, date character vectors, or datetime arrays.

Data Types: double | char | datetime

End date, specified as a scalar or an N-by-1 or 1-by-N vector using serial date numbers, date character vectors, or datetime arrays.

Data Types: double | char | datetime

Output Arguments

collapse all

Number of days between two dates based on the actual number of days, returned as a scalar or an N-by-1 or 1-by-N vector containing the number of days.

NumDays returns as a double for serial date number, date character vector, or datetime inputs for StartDate and EndDate.

 Addendum to Securities Industry Association, Standard Securities Calculation Methods: Fixed Income Securities Formulas for Analytic Measures. Vol. 2, Spring 1995.