datetime culture problems

A

adam

Hi,

I am having difficulty with the date time parse method:

try{
System.IFormatProvider format = new CultureInfo("en-
GB", true);
DateTime dateActive = DateTime.Parse
(txtDate.Text,format);
}
catch{
throw new Exception("Unable to recognise date/time
values: use format 'dd/MM/yyyy hh:mm'");
}

It works ok on some machines but not others as it
interchanges UK for US style dates, so 14/07/03 for
fourteenth of July is misterpreted as fourteenth month
and 3/7/03 as 7th March. Why is this when I have
specified an 'en-GB' cultureInfo?

I have checked the date format settings in the Regional
and Language Options of control panel and they are ok.

Adam
 
T

Thomas Scheidegger [MVP]

Hi
System.IFormatProvider format = new CultureInfo("en-GB", true);

if you expect the same format, independent from user any settings, try:
new CultureInfo("en-GB", false );

[ useUserOverride = false ]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top