What is the safest way to use select with DataTables when filtering on dates in VB.NET?
This will work in US regional settings
table.Select("[Date] = "#04/16/1984#"
This should work in german regional settgins but it thorws dateformat ex开发者_如何学JAVAcpetion
table.Select("[Date] = "#16.04.1984#"
To me it seems that datatable does not understand current regional settings. Is there a way to pass date in a certian format, so it will work in any regional setting?
To use Dates with DataTable.Select, you need use InvariantCulture Format and enclose it with #
At Debug:
? TD.Select ("fisap=#9/25/2011 00:00#").Length
20
? TD.Select ("fisap=#9.25.2011 00:00#")(0)(10).ToString
"25/09/2011 0:00:00" - (Spanish)
? TD.Select ("fisap=#9/25/2011 00:00#")(0)(10)
#9/25/2011# {Date}
I guess it depends on the underlying datastore date and time settings, as it is it that stores the information. So, if you're client application is in another regional settings format, make sure to format your date string into the right database settings.
I think this should be helpful: DateTime.Parse Method (String)
精彩评论