Remove rows not date format in datatable

Hi Everyone.

I want to filter and remove all rows which are not date format as picture.

How to do that?

Thanks in advance!
1

Hi @Mr.H,

you can use invoke code to to run IsDate method on your value.
image

That will give you a boolean value which you can save into your data table to later filter and/or delete unnecessary rows.

Alternatively you can also try to cast your value into datetime format using
convert.ToDateTime(row(0))
If it’s not a date you’ll get an exception which you can handle and convert to a boolean value and later use to decide what to do with that row.

Hope that helps :slight_smile:

BR,
Filip

2 Likes

@Mr.H
lets assume following:
grafik

Assign activity
left side: dtFiltered (DataType: DataTable)
right side:

(From d in yourOriginDataTableVar.AsEnumerable()
Where Regex.IsMatch(d(YourColNameOrIndex).toString.Trim,"\d{2}\/\d{2}\/\d{4} \d{2}:\d{2}:\d{2}") 
Select d).CopyToDataTable

As an alternate we can base it also on a dateTime Parse Check
Assume following:
grafik

Assign activity
left side: dtFiltered (DataType: DataTable)
right side:

 (From d in yourOriginDataTableVar.AsEnumerable()
 Where DateTime.TryParseExact(d(YourColNameOrIndex).toString.Trim,"dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture,DateTimeStyles.None,nothing) 
 Select d).CopyToDataTable
2 Likes

Even more simple: Use Filter Data Table Activity. Keep all rows with “/” and “:”.

1 Like

Hi Everyone.

Thanks you very much for your support!

Hi Bro @ppr

Sorry. I have another question related to your solution.

In your Code “(From d in yourOriginDataTableVar.AsEnumerable()
Where Regex.IsMatch(d(YourColNameOrIndex).toString.Trim,”\d{2}/\d{2}/\d{4} \d{2}:\d{2}:\d{2}")
Select d).CopyToDataTable"… I want to remove all XX:XX:XX and keep only Date…

How to do that ?

Thanks you!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.