I am working on one word add-in application in which I have several date picker content controls, setting the text value in to this content control also changes the format of it as per system date format.
I am setting up the DateDisplayFormat and DateDisplayLocale explicitly still it is showing date value as per system date format.
ContentControl.Range.Text = "21-12-16";
ContentControl.DateDisplayFormat ="yy-M-d";
ContentControl.DateDisplayLocale =
Microsoft.Office.Interop.Word.WdLanguageID.wdSimplifiedChinese;
My system date format : MM/dd/yyyy
-Actual result : 16-12-21 (MM/dd/yyyy)
-Expected result : 21-12-16 (yy-M-d)
I believe the problem comes from the ambiguity of Range.Text = 16-12-21
.
This can be interpreted either way, as the year 2016 or as the year 2021. Word does rely on the Windows System settings for things like interpreting what a date should be, rather than anything local. I thought, perhaps switching the order of the format and data entry might have an influence, but it does not.
Simply provide a four-digit year, which is standard good-practice every since people realized the potential "millenium" problems back in the 1990's, and there's no issue. There's also no issue when someone uses the DatePicker in the UI. So...
ContentControl.Range.Text = "2021-12-16";
ContentControl.DateDisplayFormat ="yy-M-d";
ContentControl.DateDisplayLocale =
Microsoft.Office.Interop.Word.WdLanguageID.wdSimplifiedChinese;