MATLAB: Calculate the date difference

days differenceStatistics and Machine Learning Toolbox

I have two columns StartDate and Endate the value of the columns is 'datetime'
EndDate=[ '05-Aug-2020 00:00:00'
'05-Aug-2020 00:00:00'
'07-Aug-2020 00:00:00'
'07-Aug-2020 00:00:00'
'07-Aug-2020 00:00:00'
'01-Aug-2020 00:00:00']
Start Date= ['29-Jul-2020 00:00:00'
'29-Jul-2020 00:00:00'
'31-Jul-2020 00:00:00'
'31-Jul-2020 00:00:00'
'02-Aug-2020 00:00:00'
'01-Aug-2020 00:00:00'
'02-Aug-2020 00:00:00'
'29-Jul-2020 00:00:00'
'29-Jul-2020 00:00:00']
I would like to calculate the number of days per row in the column.

Best Answer

The vectors must have the same sizes.
Use between:
DaysDiff = between(StartDate(1:numel(EndDate)),EndDate)
to get:
DaysDiff =
6×1 calendarDuration array
7d
7d
7d
7d
5d
0d
.