MATLAB: Get tenor between two time points

datedatenum

In excel, if some cells are in the format of date, then the difference of the cells gives you the tenor. How can I do that in Matlab?
To be specific I mean I already have some serial data number, say 20110610 and 20110716 (today's date and the expiration date of the contract), and I wanna get the number of days between these two dates. So in this example I'd like to get 36.
If I do: 20110716-20110610, the ans is 106, the same as
datenum(20110716)-datenum(20110610)=106
So my question is, again, how can I get 36 out of these two dates?
Thanks in advance 🙂

Best Answer

d1 = datenum('20110610','yyyymmdd');
d2 = datenum('20110716','yyyymmdd');
d2-d1