Date Time Parse

Hello, I have a table with this data.
image

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.


the following error
image

Please help…

Hi @pl.rusinov ,

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.

hi

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

@pl.rusinov ,

Check with the below Expression :

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.

returns error Assign: String ‘03/13/2023 07:57:00’ was not recognized as a valid DateTime. does not format the date in dd/ММ/yyyy format

@pl.rusinov ,

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.

Also, You could Check with the below Expression :

dateFormats = {"dd/MM/yyyy","MM/dd/yyyy HH:mm:ss"}
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.