Datetime cannot parse certain literal months
Ältere Kommentare anzeigen
I am currently working with date strings. It seems that not all dates can be interpreted using "datetime". E.g.:
datetime('05 Nov 2021','InputFormat','dd MMM yyyy','Locale','en_GB')
works fine, but
datetime('05 Sep 2021','InputFormat','dd MMM yyyy','Locale','en_GB')
throws:
Error using datetime
Unable to convert '05 Sep 2021' to datetime using the format 'dd MMM yyyy' and locale 'en_GB'.
I can not explain what is the matter with "Sep".
Akzeptierte Antwort
Weitere Antworten (1)
Jim Benjamin
am 11 Mär. 2025
0 Stimmen
Hi everyone,
I have a similar problem: I like to convert the string array s(1) = "11-Mrz-2025 10:03:47" to datetime using
s1 = datetime(s(1), 'InputFormat', 'dd-MMM-yyyy hh:mm:ss', 'Locale', 'de_DE') and I get the error
Error using datetime (line 257)
Unable to convert '11-Mrz-2025 10:03:47' to datetime using the format 'dd-MMM-yyyy hh:mm:ss' and locale 'de_DE'.
I do not know why this Input Format is not working. Thank you
1 Kommentar
The 'de_DE' abbreviation of the third month is "März":
string(datetime(2025,3,11), 'MMM','de_DE')
So your "Mrz" will not be matched. While we are here lets take a look at them all:
string(datetime(2025,1:12,11).', 'MMM','de_DE')
As far as I can tell, the Unicode date names for German are defined here:
Both "März" and "Mär" are defined, but not "Mrz". Lets try them both:
datetime('11März2025', 'Locale','de_DE','InputFormat','ddMMMyyyy')
datetime('11Mär2025', 'Locale','de_DE','InputFormat','ddMMMyyyy')
Kategorien
Mehr zu Calendar finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!