Datetime conversion from string with non-matching format does not yield an error
Afficher commentaires plus anciens
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?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Dates and Time 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!