Hi,
First of all, I get this date from web using data scraping.
However , I had this issue to filter date with format (d-MMM-yy).
I already checked other solution from other post in this forum. But it didn’t help.
I try convert using Cdate or Dateparse also no any result.
When, I filtered as below : -
It didn’t filter the date. Only show the header name.
Here I attached the date as below : -
PRDDATE
16-Dec-21
15-Dec-21
14-Dec-21
13-Dec-21
11-Dec-21
10-Dec-21
9-Dec-21
8-Dec-21
7-Dec-21
6-Dec-21
5-Dec-21
4-Dec-21
3-Dec-21
2-Dec-21
1-Dec-21
Please advice.
Yoichi
(Yoichi)
December 17, 2021, 3:44am
2
Hi,
Can you try the following expression?
ExtractDataTable = ExtractDataTable.AsEnumerable.Where(Function(r) DateTime.Parse(r("PRDDATE").ToString)>=New DateTime(2021,12,1) AndAlso DateTime.Parse(r("PRDDATE").ToString)<=New DateTime(2021,12,10)).CopyToDataTable
Note: If there is invalid date string/character (including empty) in PRDDATE column, the aboce will fails.
Regards,
1 Like
@Yoichi
Thank you for feedback.
Yes. It can filter.
But can you explain a bit what expression did ?
Yoichi
(Yoichi)
December 17, 2021, 3:59am
4
Hi,
It’s LINQ expression.
ExtractDataTable.AsEnumerable.Where(Function(r)
means iterate each row of the datatable, and filter out item which is returned False by the following expression.
DateTime.Parse(r("PRDDATE").ToString)>=New DateTime(2021,12,1) AndAlso DateTime.Parse(r("PRDDATE").ToString)<=New DateTime(2021,12,10)
This means convert item of PRDDATA column in the row to DateTime type, and compare with 2021/12/1 and 2021/12/10 as datetime type. If both true, then returns true and is kept in the datatable.
Regards,
1 Like
system
(system)
Closed
December 20, 2021, 7:52am
6
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.