hello sir
how can I get my system short date format in a label in vb. net. I try this code :

Label1.Text = System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern()

but show wrong data. all time show "M/d/yyyy" format.

I change it(to "dd/MM/yyyy") manually and by coding result is same("M/d/yyyy") please help me.....

For Change the Format:

Microsoft.Win32.Registry.SetValue("HKEY_CURRENT_USER\Control Panel\International", "sShortDate", "dd/MM/yyyy")
ddanbe commented: Thanks for marking this solved +15

Recommended Answers

All 3 Replies

Well to set the Text of your label, I would use the ToString method of DateTime with a format string. See here for examples.

Take a look here

                Dim dt As DateTime = Now
                Dim sDate As String = dt.ToString("yyyy-MM-dd")

Or you can change current's thread date pattern:

                Dim newCulture As System.Globalization.CultureInfo =
                newCulture.DateTimeFormat.ShortDatePattern = "dd-MM-yyyy"
                newCulture.DateTimeFormat.DateSeparator = "-"
                System.Threading.Thread.CurrentThread.CurrentCulture = newCulture
                Dim sDate As String = Now.ToString
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.