What date format to use in query on Data table???

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

Henk van Jaarsveld

Can somebody help me on this please,

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
 
Hi Henk,

You should be safe always using #M/d/yyyy# format. The DateTime values
stored in the DataTable are invariant of culture.

I hope this helps.

Kind regards,

Jamilu Abubakar [MSFT]
Microsoft
 
Back
Top