Datetime cannot parse certain literal months
Afficher commentaires plus anciens
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".
Réponse acceptée
Plus de réponses (1)
Jim Benjamin
le 11 Mar 2025
0 votes
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 commentaire
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')
Catégories
En savoir plus sur Calendar dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!