Carryover in Date Vectors and Strings

If an element falls outside the conventional range, MATLAB® adjusts both that date vector element and the previous element. For example, if the minutes element is 70, MATLAB adjusts the hours element by 1 and sets the minutes element to 10. If the minutes element is -15, then MATLAB decreases the hours element by 1 and sets the minutes element to 45. Month values are an exception. MATLAB sets month values less than 1 to 1.

In the following example, the month element has a value of 22. MATLAB increments the year value to 2010 and sets the month to October.

datestr([2009 22 03 00 00 00])
ans =
    03-Oct-2010

The carrying forward of values also applies to time and day values in text representing dates and times. For example, October 3, 2010 and September 33, 2010 are interpreted to be the same date, and correspond to the same serial date number.

datenum('03-Oct-2010')
ans =
      734414
datenum('33-Sep-2010')
ans =
      734414

The following example takes the input month (07, or July), finds the last day of the previous month (June 30), and subtracts the number of days in the field specifier (5 days) from that date to yield a return date of June 25, 2010.

datestr([2010 07 -05 00 00 00])
ans =
    25-Jun-2010