Click here to Skip to main content
14,449,906 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi,

I a working on VB.NET windows based application. I need to set default date format in my application.

Suppose date format in Operating System for Short date is "dd.MM.yyyy"

But i want "M/d/yyyy" format for my application. How do i convert to "M/d/yyyy" at run time.
Posted
Updated 11-Feb-20 21:45pm
Rate this:
Please Sign up or sign in to vote.

Solution 4

you can change system's date format runtime using this code
(will change format in regional language settings)
Imports System.Threading

Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US", False)

Microsoft.Win32.Registry.SetValue("HKEY_CURRENT_USER\Control Panel\International", "sShortDate", "M/d/yyyy")

Happy Coding!
:)
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Hi,

You can simply use below code,

DateTime currentDate = DateTime.Now;
var dateResult = currentDate.ToString("M/d/yyyy");


Hope this will help you,

Thanks
-Amit Gajjar
   
Comments
kals84 26-Jul-12 6:43am
   
this code is not working :(
AmitGajjar 26-Jul-12 7:06am
   
can you post your code ? what error you have ?
Rate this:
Please Sign up or sign in to vote.

Solution 5

Protected Sub Application_BeginRequest(sender As [Object], e As EventArgs)
	Dim newCulture As CultureInfo = DirectCast(System.Threading.Thread.CurrentThread.CurrentCulture.Clone(), CultureInfo)
	newCulture.DateTimeFormat.ShortDatePattern = "dd-MMM-yyyy"
	newCulture.DateTimeFormat.DateSeparator = "-"
	Thread.CurrentThread.CurrentCulture = newCulture
End Sub
   
Comments
Member 12254178 7-Feb-16 11:00am
   
Hi, I am placing this code in code window. but its not affecting.
Actually I am following a date format like "dd/MM/yyyy" in my application using vb.net 2010 express. But system date formats has different for each system. So I need to set my date format globally for my application (Not to change system date settings. Only for my application). It should not influence with any system date format. Can you please explain the step procedure.
Thank you.
Rate this:
Please Sign up or sign in to vote.

Solution 6

If you are using the DateTimePicker1 then you can set the DateTimePicker1 properties as Custom as like you "M/d/yyyy" and format is "Custom" it is simple method.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100