Datetime conversion from string with non-matching format does not yield an error
Mostrar comentarios más antiguos
I am reading in some data and want to check the format before converting. Interestingly, specifying the InputFormat with 4 digits while only having 2 digits does not yield an error, but rather trails the year with 00:
Reading in a date like
datetime('21.02.12','InputFormat', 'yy.MM.dd')
yields the desired output
datetime
12-Feb-2021
However, explicitly stating a four-digit year
datetime('21.02.12','InputFormat', 'yyyy.MM.dd')
does not produce an error, but rather the output
datetime
12-Feb-0021
Rather than shifting to the first century, I want to get an error message, hinting at the invalid date format. How can I realize this?
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Dates and Time en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!