• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

American Dates

We have a vb.net app.
 
Is there a way that we can override the regional settings so that all dates are displayed as dd/mm/yyyy format throughout the application?
This is to overcome where the user has it set to American or mm/dd/yyyy which gives some functions in our application a problem.
 
Target Systems are Vista, Win XP , Server 2003 & Server 2008
 
Thanks
0
LKearney
Asked:
LKearney
  • 7
  • 5
2 Solutions
 
abelCommented:
Yes, you can do this with the following line somewhere during the load of your app:

Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US")

Open in new window

0
 
abelCommented:
Apologies, little mistake, should be both UICulture and Culture. This line of Brad Adams explains the difference/similarities:

To be more explicit, use the CultureInfo instance returned by a thread's CurrentCulture property to format any numeric or date, and the one returned by CurrentUICulture to look up any resource. People are often confused between the two properties.


' change the culture globally for this app '
Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US")
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture

Open in new window

0
 
LKearneyAuthor Commented:
Thanks Abel,

will give that a try in a small vb.net app.

Take it, it changes the Date Format in Regional Settings for the user for good, or just on this running of the app??

Notice on Vista that the user can change the format of the date as well. i.e. to a d/m/yy format or something else. Will using the above code change it to an English Date in format dd/mm/yyyy, if the user has changed the format of date previously??

Thanks so much for your help, it is most appreciated.

Larry
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
abelCommented:
> or just on this running of the app??
just on the app.

> Will using the above code change it to an English Date in format dd/mm/yyyy, if the user has changed the format of date previously??
it will not use a user-specified format. Which means: yes, it will use the english date format
0
 
LKearneyAuthor Commented:
We ran it in a small app and it works absolutely brilliantly for a system with regional settings US. Thank you so much.

Can I ask an additional question on this issue, if I may

We ran that code and ask for Msgbox(Today) and it returns in the date format for whatever was set for that region (UK) in the first place.

However, have one issue in Vista, where the date format for a specific region can be set to many formats(e.g. yyyy-mm-dd), so when we set it to en-GB as per your code, it leaves the format as was set for that region.

How can we set the Current Format to UK (your code does this perfectly above) but also set the date format for that current region to dd-mm-yyyy as our default.

We'd be most grateful for your guidance, as this would be our perfectist conclusion to this issue, and could sleep easy tonight, never to worry about what if the dates are wrong format!!

Thanks again abel
0
 
abelCommented:
That's an interesting question and since I'm on Vista myself, I can test it, too. But I don't know a solution, yet, apart from writing your own wrapper functions. You know, the problem with this is, that Microsoft tries to give the entire Windows system, and any applications running on it, the same look and feel for users. That means, you have to take that extra step to be disobedient to that rule...

I'll look into it, though.
0
 
LKearneyAuthor Commented:
Abel thanks so much.

You'll be getting the points regardless. As we'll cover 95% of issues that might occur for our users with your solution. The extra issue has arisen beacause fo a "what if" question really. It's be brilliant is we could solve though!!

I was looking into it, and found something around on google around a search for

"Date Format Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture"

but got a little confused with it all.

Thanks so much for your help!
0
 
abelCommented:
Actually, this appears to be very easy. Just set the DateSeparator in your newly created culture:



' overriding culture settings '
Dim culture As CultureInfo  = System.Globalization.CultureInfo.CreateSpecificCulture("en-US")
culture.DateTimeFormat.DateSeparator = "/"
Thread.CurrentThread.CurrentCulture = culture
Thread.CurrentThread.CurrentUICulture = culture

Open in new window

0
 
abelCommented:
When you browse through that CultureInfo object, you will see that you can actually override just about anything. So, if you want to be totally in control for numbers, dates etc, you can do this.
0
 
LKearneyAuthor Commented:
You are a god damn hero, and guru all rolled into one!!

in way of a viritual british pint, I've added another 50 points onto Points. Wish it was more, but running low at the moment.

Thanks so much.

To anyone searching in the future, this is the fix!!!
0
 
LKearneyAuthor Commented:
Excelklent Answer. Going away from post with more than my expectations in simplicity and speed of solution.

Thanks so much Abel.
0
 
abelCommented:
> Excelklent Answer. Going away from post with more than my > expectations in simplicity and speed of solution.> Thanks so much Abel.

Those are nice compliments (had to repeat them here because they are not visible to others then you and me). Thanks so much and hope to help you in the future.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now