My input S.no. date. Value
12/31/2022 24:07:08 AM. 45
03/02/2022. 56
03/28/2022. 78
03/16/2022. 56
03/08/2022. 55
My start date is 03/01/2022 and end date is 03/31/2022. Dates falling between start and end is My output should be
S.no. date. Value
03/02/2022. 56
03/28/2022. 78
03/16/2022. 56
03/08/2022. 55
If no date is falling it should return as empty datatable
1 Like
@sruthesanju ,
Is the data in Datatable?
Thanks,
Ashok
1 Like
@sruthesanju ,
Make sure you startDate & endDate are DateTime Type like
Use this LINQ query.
(From row In dt.AsEnumerable()
Let dateValue = DirectCast(row("DateColumn"), DateTime)
Where dateValue >= startDate AndAlso dateValue <= endDate
Select row).CopyToDataTable
Thanks,
Ashok
1 Like
rlgandu
(Rajyalakshmi Gandu)
March 1, 2024, 7:17am
5
@sruthesanju
filteredDataTable = (From row In yourDataTable.AsEnumerable()
Let dateValue = DateTime.ParseExact(row("Date").ToString(), "MM/dd/yyyy", CultureInfo.InvariantCulture)
Where dateValue >= DateTime.ParseExact("03/01/2022", "MM/dd/yyyy", CultureInfo.InvariantCulture) AndAlso
dateValue <= DateTime.ParseExact("03/31/2022", "MM/dd/yyyy", CultureInfo.InvariantCulture)
Select row).CopyToDataTable()
1 Like
lrtetala
(Lakshman Reddy)
March 1, 2024, 7:19am
6
Hi @sruthesanju
Can you try the below
StartDate=DateTime.ParseExact("03/01/2022", "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)
EndDate=DateTime.ParseExact("03/31/2022", "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)
Input:
Output:
Regards,
1 Like