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)?
Asked
Active
Viewed 952 times
0
-
7Why don't you use `DateTime.TryParse`? – Tim Schmelter Oct 30 '13 at 22:37
-
@Tim - I want to know if there is a way with isDate() function. – user1176058 Oct 30 '13 at 22:38
-
3Yep, you shouldn't really rely on IsDate: http://stackoverflow.com/questions/4338025/isdate-function-returns-unexpected-results – Daniel Abou Chleih Oct 30 '13 at 22:38
-
2Are you from the UK? This is culture-based, based on the machine's OS that is currently running the code. You need to look at changing the current thread's UI culture to be able parse using the en-US culture. – ps2goat Oct 30 '13 at 22:39
1 Answers
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