0

I am using this function and it looks like it works only with UK data format (dd/mm/yyyy). How to use this function for US date format (mm/dd/yyyy)?

user1176058
  • 642
  • 1
  • 8
  • 21

1 Answers1

2

Microsoft.VisualBasic.Information.IsDate depends on the current culture of the thread the code is running on. So to make it work for US date format in all cases, you would have to switch the current culture:

System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-US")
Dim isDate As Boolean = Microsoft.VisualBasic.Information.IsDate("10/13/2013")

This makes that method rather tricky to use.


It's easier to use Date.TryParse as you can specify the culture each time you use it:

Dim d As Date
Date.TryParse("10/13/2013", New System.Globalization.CultureInfo("en-US"), Globalization.DateTimeStyles.None, d)
Szymon
  • 42,577
  • 16
  • 96
  • 114