Hi,
We are writing the .net application that should always work in en-US culture, regardless of the control panel settings.
I was able to force the GUI culture to be en-US by the following code
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-CA", true);
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-CA", true);After that the DateTimePicker components are always displayed in en-US culture, which is good. But the PROBLEM is that if I retrieve the the DateTimePicker value in the code, it comes in Control Panel settings again. To retrieve the value i use the following:
pickerDate.Value.ToString("ddMMM").ToUpper()
Is there any general way to make EVERYTHING work in the needed culture
Thanks,
Belochka

Strange prolem with Culture settings
Ravi Krishnaswamy
Does it really work for you if you, for example, go to Control Panel/Regional and Language Options and:
1. In standards and formats you choose Spanish.
2. In avanced panel for non-unicode apps you also choose Spanish.
Then you do the suggested culture setting in the program. Does it show the date and the calendar in English Also, does it come in desired format when you use ...Value.ToString("ddMMM") for the DateTimePicker component
Dinesh Rathi
The article kh links to has the answer.
Those control are common controls and always uses the regional settings for the user. Changing the culture in your application has no effect on the datetime/month pickers.
overgaard
Yes, i agree. What i'm saying is that we used Value.ToString("ddMMM") in ALL our classes. Some of them are compiled in DLLs and nobody wants to change their code. But your suggestion requires changing the code, if i understood right. I am trying to find the general way of resolving this problem such as setting the main system culture or something
Kasper Wegmann
Gerry Whitworth
to force a short month name in a particular culture you could of course do something nasty like this..
string month = CultureInfo.GetCultureInfo("en-US").DateTimeFormat.AbbreviatedMonthNames[myDateTime.Month];
(not tested btw)
kh
Jake2
Thanks for trying to resolve my issue
Sorry for mesleading about en-US and en-CA. This is not an issue, as long as we have English. What happens if you have different language (i mean with different letter months like "Abr" instead of "Apr" or "Mia" inatead of "May") Calenday is also not a problem, i just mentioned it to give an example.
Ed Blankenship
Yes, but this would require going through all our xml communicator classes and change the code. Changing the Control Panel settings would be even easier in this case
cjb-
I did the following.
1) Go to Control Panel\Regional Settings and change Standards and Formats from English (US) to English (Canada).
2) Verify the culture changed by checking the clock to ensure that instead of saying "Thursday April 20, 2006" that is said "April 20, 2006". I also verified that the short date changed from 4/20/2006 to 20/04/2006.
3) Create a simple app that contains a textbox and DateTimePicker. Whenever the value of the DTP changes the textbox Text propert is set to dtp1.Value.ToString().
4) Change the DTP value and ensure that it displays the correct cultural string (en-CA).
5) Modify the code to force the current thread to use en-US for both CurrentCulture and CurrentUICulture.
6) Verify that even though Control Panel and my clock shows time in en-CA that the app is using en-US.
This is the extent of my testing. I did not verify the Calendar control behaved properly as you did not originally mention you were using it. I also made no other changes to any control panel settings.
Michael Taylor - 4/20/06
iknowstuff
Ok, sorry again. I'll try to clearify the problem.
So, the main problem is that we use the DTP values in xml calls. The xml call requires the date to be in following format "20Apr" for April 20. But, for our new mexico users we get the error reports, from which we find out that the dates passed to the webservice reflect the Control Panel settings i.e. "20Abr" instead of "20Apr" or "05Mia" instead of "05May".
I use DTP.Value.ToString("ddMMM") to retrieve the value.
So, my problem is that i was able to make the DTP display the date always in English, but this was all i could do. In the code using the above call it comes as "05Mia" again, however it displays "05May".
Matholroyd
Canada or US does not really matter
The real problem is that it comes in Spanish for our mexico users.
The code sample that i gave is inserted into the windows form constructor before the InitializeComponents() call i.e. exactly as suggested in all msdn tutorials. It has the following effect:
1. DateTimePicker displaying date was changed to the desired format, which is good but not enough
What did not work
1. The calendar (appering when you click the picker's down arrow) still shows in Spanish.
2. In the code (separate thread) i retrieve the date as ddMMM and it comes as, for example, "20Abr" instead of "20Apr" which is fatal, becuase we use this data for all xml calls
I've read the suggested msdn resolution from the previous post. Is there really no way to resolve this issue programmatically rather than changing the Control Panel settings
Oleg_R
Belochka
The issue you observe is described here:
http://support.microsoft.com/default.aspx scid=kb;en-us;889834
kh
BillCondo
I believe there is some confusion on the issue here. The original question mentioned nothing about the UI of the control. The question said the returned DateTime value was not showing up in the correct culture. This is independent of the UI and where the value came from.
The KB article mentioned only applies to the UI of the control and not the underlying Value property. Indeed the DTP and Calendar controls probably use the UI set up by the control panel settings but again this was not what the original question was about.
Perhaps the original poster can clarify what the problem is and what they would like to see resolved
Michael Taylor - 4/20/06
Jeff Hedrick
The ToString method of DateTime uses Thread.CurrentThread.CurrentCulture to format dates and times. This is standard. CurrentCulture is used to format values when not being displayed in a UI and CurrentUICulture when being used for UI.
Are you sure you've set everything up properly I verified that it works properly on my machine. Note that the sample you gave is setting the culture to English (Canada) and not English (United States). The code for what you wanted is en-US. I switched my machine to use en-CA and the dates appeared as dd/MM/yyyy. This is how the DTP showed the value when I flushed it to the text box. I then forced the culture back to en-US and the dates showed up properly as MM/dd/yyyy.
Michael Taylor - 4/20/06
Knut G