Why does DATENUM give me an error message when I pass German date strings as input arguments in MATLAB?

11 views (last 30 days)
I have set the locale settings on my computer to German. When I execute the following command in MATLAB:
d = dir;
A structure is returned that contains a field called 'date'. However, this field contains German time stamps. For example:
11-Dez-2007 08:23:16
When I pass the above date string to DATENUM as follows:
datenum('11-Dez-2007 08:23:16')
I receive the following error message:
??? DATENUM failed.
Failed to parse date string.
Error using ==> datevec at 217
Failed to lookup month of year.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
In MATLAB 7.5 (R2007b), date strings are derived from the locale settings set by the user on the system. The Locale Settings are available from:
Start -> Settings -> Control Panel -> Regional and Language Settings
DATENUM uses a locale database that may or may not be the same as the locale settings on your system. Therefore, DATENUM is sometimes unable to recognize date strings originating from locale settings.
To work around this issue, use the "datenum" field on the structure variable returned by the DIR command. For example:
d = dir;
d.datenum
will produce the corresponding serial date numbers of the file time stamps in MATLAB.
Historical information about the behavior of MATLAB R14SP3 through R2008b:
1. The MATLAB releases R14SP3, R2006a and R2006b do not include a "datenum" field in the structure returned by the function DIR. The field "date" returns the date in English format.
2. The MATLAB release R2007a includes a "datenum" field in the structure returned by the function DIR for the first time. The field "date" still returns the date in English format.
3. Starting with MATLAB release R2007b, the "datenum" field is included in the structure returned by the function DIR, but the field "date" returns the date by using the format specified in the system locale settings.
Here's an example for a machine that uses German system locale settings:
- R14SP3, R2006a, R2006b
------------------------------
>> d = dir
d =
4x1 struct array with fields:
name
date
bytes
isdir
>> d.date
ans =
07-Oct-2008 10:17:11
------------------------------
- R2007a
------------------------------
>> d = dir
d =
4x1 struct array with fields:
name
date
bytes
isdir
datenum
>> d.date
ans =
07-Oct-2008 10:32:00
------------------------------
- R2007b, R2008a, R2008b
------------------------------
>> d = dir
d =
4x1 struct array with fields:
name
date
bytes
isdir
datenum
>> d.date
ans =
07-Okt-2008 10:32:00
------------------------------

More Answers (0)

Categories

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

Products


Release

R2007b

Community Treasure Hunt

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

Start Hunting!