Why does the DATEVEC function return inaccurate results in MATLAB 7.0 (R14)?

1 view (last 30 days)
The following steps reproduce this behavior:
1) Close any open instance of MATLAB.
2) Change the time zone on your machine to one of the +02:00 zones (i.e., +02:00 Cairo).
3) Restart MATLAB.
4) Execute the following commands:
datevec(['16-Apr-07';'27-Apr-07'])
This returns:
ans =
2007 4 16 0 0 0
2007 4 26 23 0 0
when it should return:
ans =
2007 4 16 0 0 0
2007 4 27 0 0 0
However, if the order of the two dates are reversed, the date vectors returned are correct:
datevec(['27-Apr-07';'16-Apr-07'])
ans =
2007 4 27 0 0 0
2007 4 16 0 0 0

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This bug has been fixed for Release 14 SP1 (R14SP1). For previous releases, please read below for any possible workarounds:
We have verified that there is a bug in MATLAB 7.0 (R14) in the way it handles date vectors. This is a time zone specific issue which occurs only in certain time zones.
To work around this issue, perform the following steps
1. Download the attached files datezip.m and datezip.zip into the same directory.
2. From within MATLAB, run the function datezip.m. This will replace all the necessary MEX-functions for each platform associated with the files:
dtstr2dtvecmx
dtstr2dtnummx
addtodatemx
within the $MATLAB\toolbox\matlab\timefun\private directory.
3. Restart MATLAB.
4. After restarting MATLAB, issue the following command at the MATLAB prompt:
rehash toolboxcache

More Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!