MATLAB: Does a the DATESTR function incorrectly interpret a date passed to it in 24-hour format

datenumMATLAB

I am passing a date to the DATENUM function in the 24-hour format as follows:
datestr(datenum('19-May-2000 24:00:00'))
However, this returns
ans =
20-May-2000
MATLAB seems to be advancing the date by one day.

Best Answer

MATLAB interprets the 24 Hour time range as 00:00 to 23:59. Hence using 19-May-2000 24:00:00 is treated as 20-May-2000 00:00:00.
As a workaround please find attached a sample program that treats the 24-hour time range as 00:00 - 24:00. If the time is found to be 24:00:00 (using the STRFIND function), then the day is subtracted by 1 following which 24:00:00 is added to it.
The function may be invoked as follows:
time24('19-May-2000 24:00:00')
This returns the following:
ans =
19-May-2000 24:00:00
Barring this special case (24:00:00), the TIME24 function exhibits the same functionality as the DATESTR function.