MATLAB: Does DATENUM appear to return an incorrect result when I use a date format number as the second input argument, ‘F’

MATLAB

If I execute the following code
datenum('03/08/2009',23)
datenum('03/08/2009',24)
datenum('03/08/2009','dd/mm/yyyy')
I see the result
ans =
733840
ans =
733840
ans =
733988
Note that the first two commands return the same date number, although I used a different format number. If I use the format string instead, as in the third command, I see the expected result.

Best Answer

This change has been incorporated into the documentation in Release 2010b (R2010b). For previous releases, read below for any additional information:
This occurs because the format, 'F', input argument to DATENUM must be a format string. As described in the documentation, if the second input argument is numeric, DATENUM treats this input as the pivot year, using the syntax
N = datenum(S, P) converts date string S, using pivot year P. If the format of date string S is known, use the syntax N = datenum(S, F, P).
The documentation for DATENUM states that
"All date strings in S must have the same format, and that format must match one of the date string formats shown in the help for the datestr function."
However, it should explicitly state that only format strings, and not format numbers, may be used with the DATENUM and DATEVEC commands.
In addition, the Note below the table of 'Standard MATLAB Date Format Definitions' in the DATESTR documentation should read:
Note: dateform numbers 0, 1, 2, 6, 13, 14, 15, 16, and 23 produce a string suitable for input to datenum or datevec. Other date string formats do not work with these functions unless you specify a date form *string* in the function call.