DataView RowFilter & DataTable.Select DateTime conditions in .Net

DataView RowFilter & DataTable.Select DateTime conditions in .Net

One needs to be very careful while using datetime in conditions for DataView.RowFilter or DataTable.Select. Because it is not that straight forward as comparing against string to numbers.

The string representation of datetime format depends upon your server/computer's culture or your application's thread culture. While the rowfilter or select method needs the datetime formatted as invariant or en-US culture.

Consider the scenario in which you are running your application running in Spanish culture, the following condition will fail in that case:

dataView.RowFilter = "Date = '" + dateVariable.ToString() + "'";


To overcome this kind of culture specific issues:

  1. Always use Date values enclosed within sharp characters # #
  2. Use culture invariant string as condition. For above mentioned example, the following will always work
dataView.RowFilter = String.Format(CultureInfo.InvariantCulture.DateTimeFormat, "Date = #{0}#", dateVariable);

About Author

Kiran Beladiya

Co-Founder

Kiran Beladiya is the co-founder of The One Technologies. He plays a key role in managing the entire project lifecycle, from discussing ideas with clients to overseeing successful releases. Deeply passionate about technology and creativity, he is also an avid writer who continues to nurture and refine his writing skills despite a demanding schedule. Through his work and writing, Kiran Beladiya shares practical insights drawn from real-world experience.

Certified By