Problem with datetime in German
    14 views (last 30 days)
  
       Show older comments
    
From a German language spreadsheet I have the following DateString: '21.Okt.2020' 
where Okt is short for October.
How to read this as a datetime? According to the documentation the following should work, but unfortunately doesn't:
datetime('21.Okt.2020','Locale','de_DE','InputFormat','dd.MMM.yyyy')
Any advice would be greatly appreciated.
Regards
0 Comments
Accepted Answer
  Stephen23
      
      
 on 3 Dec 2021
        There does seem to be a problem with DATETIME handling the period characters (below).
Workaround: replace/remove the period characters, as per my first two examples.
datetime('21Okt2020','Locale','de_DE','InputFormat','ddMMMyyyy')
datetime('21-Okt-2020','Locale','de_DE','InputFormat','dd-MMM-yyyy')
datetime('21.Okt.2020','Locale','de_DE','InputFormat','dd.MMM.yyyy')
2 Comments
  Stephen23
      
      
 on 3 Dec 2021
				In case anyone suggests to put the period character inside single quotes:
datetime('21.Okt.2020','Locale','de_DE','InputFormat','dd''.''MMM''.''yyyy')
More Answers (2)
  Eric Sofen
    
 on 3 Dec 2021
        We’re aware of the issues with parsing month abbreviations in some locales, and we're looking at ways to improve this. In this case, the "." following Okt is treated as part of the month abbreviation by the internationalization library we use. For now, the datetime format that works to parse the timestamp is:
datetime('21.Okt.2020','Locale','de_DE','InputFormat','dd.MMMyyyy')
(Notice no period after MMM.)
0 Comments
  Walter Roberson
      
      
 on 3 Dec 2021
        Observe:
datetime('21.Oct.2020', 'InputFormat', 'dd.MMM.yyyy', 'Format', 'dd.MMM.yyyy')
So using dots is possible for English.
datetime('21-Okt-2020', 'Locale', 'de_DE', 'InputFormat', 'dd-MMM-yyyy', 'Format', 'dd.MMM.yyyy')
And using dashes is okay for German
datetime('21.Okt-2020', 'Locale', 'de_DE', 'InputFormat', 'dd.MMM-yyyy', 'Format', 'dd.MMM.yyyy')
and dot between the day and the month is ok in German
datetime('21.Okt.2020', 'Locale', 'de_DE', 'InputFormat', 'dd.MMM.yyyy', 'Format', 'dd.MMM.yyyy')
But dot between the year and the month is not okay in German.
I do not know why this is... but see the following
2 Comments
  Walter Roberson
      
      
 on 3 Dec 2021
				
      Edited: Walter Roberson
      
      
 on 3 Dec 2021
  
			datetime('21.Okt..2020', 'Locale', 'de_DE', 'InputFormat', 'dd.MMM.yyyy', 'Format', 'dd.MMM.yyyy')
I do not know quite what to make of this.
See Also
Categories
				Find more on Calendar in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


