Datetime cannot parse certain literal months
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Thomas Cimiega
el 9 de Dic. de 2022
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".
0 comentarios
Respuesta aceptada
Stephen23
el 9 de Dic. de 2022
Editada: Stephen23
el 9 de Dic. de 2022
According to american logic, the british three-letter appreviation of September is "sept":
datetime('05 Nov 2021','InputFormat','dd MMM yyyy','Locale','en_GB')
datetime('05 Sept 2021','InputFormat','dd MMM yyyy','Locale','en_GB')
PS: to be fair, the DATETIME documentation does not state that abbreviations must be three letters (although I suspect that many english speakers would assume that it does), it actually states "MMM Month, abbreviated name", thus allowing any length abbreviation.
However the documentation does not list those abbreviations anywhere, nor the full months names or anything else, but it does link to the Unicode documentation, where if one spends enough time digging, one might find a reference to how dates are abbreviated in every supported language (I cound not find it).
3 comentarios
Les Beckham
el 9 de Dic. de 2022
Wow, indeed!
Without the Locale specification it errors with the 't' and works without it (in the US anyway)!
I would consider filing a bug report: report a bug
Más respuestas (1)
Jim Benjamin
el 11 de Mzo. de 2025
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 comentario
Stephen23
el 11 de Mzo. de 2025
Editada: Stephen23
el 11 de Mzo. de 2025
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')
Ver también
Categorías
Más información sobre Calendar en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!