We help IT Professionals succeed at work.

Change Date Format in Regional Settings

gloier
gloier used Ask the Experts™
on
Hi,

I need to change the Date format in regional settings in my project using VB.Net 2008.
I wrote the following code

        Dim TmpDateFormat As System.Globalization.CultureInfo
        TmpDateFormat = New System.Globalization.CultureInfo("en-US")
        TmpDateFormat.DateTimeFormat.ShortDatePattern = "dd-MM-yyyy"
        System.Threading.Thread.CurrentThread.CurrentCulture = TmpDateFormat

When I run this code there is no error. But  Date format not changed in regional setting.

Help me to correct my code.
Thanks and Regards
Gloier
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Why do you need the dateformat to change? Can't you change the dateformat there where you use it?
Or create another culture that has "dd-MM-yyyy" as the normal date format?
Shahan AyyubSenior Software Engineer

Commented:
try this:

        Dim TmpDateFormat As System.Globalization.CultureInfo
        TmpDateFormat = New System.Globalization.CultureInfo("en-US")
        TmpDateFormat.DateTimeFormat.ShortDatePattern = "d-M-yyyy"
        System.Threading.Thread.CurrentThread.CurrentCulture = TmpDateFormat

single 'd' and single 'M' was required.
Commented:
hi shahan,
the format you given d-M-yyyy  is not  worked.
I give the date  format  as dd/MM/yyyy. I change the separator as / . Now it works, the date format is changed.
Anyway thanks for your suggestion.
 
Regards
Gloier
 
Shahan AyyubSenior Software Engineer

Commented:
I posted you the code after testing. I worked for me this way. If you will see the pattern of ShortDatePattern then you will find d-M-yyyy. That's why I post it.