I need to filter the date from column “b” , determine which day of the week it is and filter with the data from column “c”. I use the following condition that worked until date 12.03. But dated 13.03 does not work.
Is it possible for you to provide the used Expression in the form of Text in here ? You could use the </> Preformatted text option to enter the Expression so that the format remains same.
dt.AsEnumerable.Where(Function (x) CDate(DateTime.Parse(x(“Date and time of order sent”).ToString, System.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”)).DayOfWeek.ToString = “Monday” And x(“Type of order”).ToString = “Close Account”).CopyToDataTable.Rows.Count
dt.AsEnumerable.Where(Function (x) x("Type of order").ToString = "Close Account" andAlso DateTime.ParseExact(x("Date and time of order sent").ToString, "dd/MM/yyyy",System.Globalization.CultureInfo.InvariantCulture).DayOfWeek.ToString = "Monday").Count
I have modified the expression a bit and excluded CopyToDatatable.Rows as i think it is not needed for your case, as you are trying to get the count only.
In that case we would ask you to Check with the Below Post. Or Perform a Debug and check the value of the Datatable in the Locals or Immediate Panel.
We should be able to find different formats of date values in it. Once identified we can use those formats within the DateTime.ParseExact() method to parse the date properly.
dt.AsEnumerable.Where(Function (x) x("Type of order").ToString = "Close Account" andAlso DateTime.ParseExact(x("Date and time of order sent").ToString, dateFormats,System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).DayOfWeek.ToString = "Monday").Count
Here, dateFormats is a type of String Array variable.