locked
Filter rows in Datatable using a datetime RRS feed

  • Question

  • User1163315901 posted

    Hi all,

     I have a DataTable that has two columns of type DateTime. The page that contains the Datatable has the UICulture and Culture parameters programatically assigned (to either nl-NL or en-US).

    When I have the english locale, the filter works fine. However, when I have the dutch locale, I get a System.FormatException: "String was not recognized as a valid DateTime". This happens when the value of  "e.Day.Date"  is of 1st of October 2007, which in Dutch  and English would get different abbreviations: (01 Oct 2007 and 01 Okt 2007).

    I have tried to format the dates with a short date format, but then it stops working at all. Does anyone have a hint?

    Dim strRowSelect As String = String.Format("{0} <= #{2}# AND {1} >= #{2}#", m_StartDateField, m_EndDateField, Format(e.Day.Date, "dd MMM yyyy"))
    Dim dt As DataTable = Cache("dtEvents")
    Dim rows() As DataRow = dt.Select(strRowSelect)
    
    Friday, August 24, 2007 9:19 AM

Answers

  • User1163315901 posted

     Thanks for the response, but unfortunately it didn't work. I decided then to play with all possible date/time formats when I finally got it working for all locales with the short american date format (DD/MM/YYYY).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 28, 2007 4:54 AM

All replies

  • User408020426 posted

    Can you use:

    Dim ci As Globalization.CultureInfo = New Globalization.CultureInfo("nl-NL")

    ci.Calendar

    ci.Calendar is a public property. If you display this calandar instead of your default calendar will it work?

    Also try:

    DateTime.GetDateTimeFormats() this will get all the acceptable datetime formats for that culture.

     Also you may need to convert your nl-NL datetime when filtering.

    See: http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression.aspx

    Friday, August 24, 2007 11:51 AM
  • User1163315901 posted

     Thanks for the response, but unfortunately it didn't work. I decided then to play with all possible date/time formats when I finally got it working for all locales with the short american date format (DD/MM/YYYY).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 28, 2007 4:54 AM