Resend (No answer) - What date format when queriing on data table

  • Thread starter Thread starter Henk van Jaarsveld
  • Start date Start date
H

Henk van Jaarsveld

Nobody reacted on the question below yet, maybe it is a stupid
question, but can somebody then please explain why it is stupid :-)


When queriing on a date on a DataTable a thought I should use the
Date.ToShortDateString() format, for instance like this:

DataRow[] resultRows = dataTable.Select(string.format("STARTDATE <=
#{0}#", dateArgument.ToShortDateString()));

However, I get the impression that a DataTable always expects the
dateformat "M/d/yyyy" no matter what the Locale of the Datatable is.
Because on a system with the dutch language (nl-NL) and the Locale of
the DataTable being dutch, it still expects the "M/d/yyyy" format and
not the "d/M/yyyy" format that is the short datestring format for
dutch. I worked around it by hardcoding the format to "M/d/yyyy" like
this:

DataRow[] resultRows = dataTable.Select(string.format("STARTDATE <=
#{0}#", dateArgument.ToString("M/d/yyyy")));

However this is not very satisfactory, because I have no guarantee
that DataTable really wants this format independent of its Locale.

Can somebody give me the answer to the question WHAT date format does
a data table really expect and is it and how is it dependent on the
Locale or some other localisation setting?

Regards,
Henk van Jaarsveld
 
Henk,

The format of the date stored in the dataset is in a
locale-independent binary format (such as
System.DateTime). When you convert strings to and from
database types, the conversion routines will use either a
specified locale or a default locale.

However, when you pass a string literal to the DataSet or
DataTable to specify filter or search criteria, you need
to provide a string literal which does not go through
locale conversions. By convention, SQL Server and VB.Net
use the format of #mm/dd/yyyy# as you have found. I can't
find any documentation which directly relates this to the
Search method, but the VB.Net usage is in the language
reference section 2.4.6.

Hope this helps,

Neil.
 
Back
Top