Need to check if any dates falls between the two given dates

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 :slight_smile:

1 Like

Yes it is in data table

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 :slight_smile:

1 Like

@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

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:

image

Output:

image

Regards,

1 Like