MATLAB: Calculate the number of days between two datetimes

datetime

How to calculate the number of days between two datetimes?
days(between(day1,day2)) does not work:
"Error using days (line xxx) Input data must be a real, numeric array."

Best Answer

You can do:
days(day2-day1)
The issue is that the between function returns a calendarDuration and this is measured using variable time-frames like months and years which contain different numbers of days.