Hi,
Can someone help me in filtering dates.
I want to filter below data table with creation date … creation date type is string
Condition is filter → creation date in DT should be greater than current date -30 days(05/08/2023) … that means from below table I want to get records of (05/22/2023 and 05/17/2023)
I tried below but it is not working
→ I got Target date = current date-30 [ d30daysback = (today.AddDays(-30)) ]
→ Converted to string [ str30daysBack = Convert.ToDateTime(d30daysback).ToShortDateString ]
→ Filterd like below
Find below attached excel
Report.xlsx (545.2 KB)
@ppr
Anil_G
(Anil Gorthi)
June 7, 2023, 6:16pm
2
@Mandava_Naresh
You should not be doing by converting to string
Please use it like a date only to filter dates
Try usingn nOw.adddays(-30) only or use Cdate(now.adddays(-30).ToString("MM/dd/yyyy"))
Alternately you can use linq to filter as well
dt = Dt.AsEnumerable.Where(function(x) Cdate(x("Current Date").ToString) >= Cdate(now.adddays(-30).ToString("MM/dd/yyyy"))).CopyToDataTable
Cheers
Cheers
@Anil_G linq worked … Thank you very much
1 Like
system
(system)
Closed
June 10, 2023, 6:21pm
4
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.