Filter Datatable Using Linq Datetime Format

Hello All!,

I can’t use filter datatable. Because “Columns1” format is “23.01.2024” “Columns2” format is “24.01.2024”
girisTarihi variable(“23.12.2023”) has to between Column1 and Column2

image

Hi,

How about the following sample? This assumes Column1<Column2

arrDr = dt.AsEnumerable.Where(Function(r) DateTime.ParseExact(r("Column1").ToString(),"d.M.yyyy",System.Globalization.CultureInfo.InvariantCulture)<=DateTime.ParseExact(girisTarihi,"d.M.yyyy",System.Globalization.CultureInfo.InvariantCulture) AndAlso DateTime.ParseExact(r("Column2").ToString(),"d.M.yyyy",System.Globalization.CultureInfo.InvariantCulture)>=DateTime.ParseExact(girisTarihi,"d.M.yyyy",System.Globalization.CultureInfo.InvariantCulture)).ToArray()

Sample
Sample20240125-7.zip (3.3 KB)

Regards,

Hi @Betul_Dundar

Assign
girisTarihi = 23.12.2023

DT=IF(DT.AsEnumerable _
    .Where(Function(r) 
        DateTime.ParseExact(r("Column1").ToString(), "d.M.yyyy", System.Globalization.CultureInfo.InvariantCulture) <= DateTime.ParseExact(girisTarihi, "d.M.yyyy", System.Globalization.CultureInfo.InvariantCulture) AndAlso
        DateTime.ParseExact(r("Column2").ToString(), "d.M.yyyy", System.Globalization.CultureInfo.InvariantCulture) >= DateTime.ParseExact(girisTarihi, "d.M.yyyy", System.Globalization.CultureInfo.InvariantCulture)
    ).ToArray().Count>0,DT.AsEnumerable _
    .Where(Function(r) 
        DateTime.ParseExact(r("Column1").ToString(), "d.M.yyyy", System.Globalization.CultureInfo.InvariantCulture) <= DateTime.ParseExact(girisTarihi, "d.M.yyyy", System.Globalization.CultureInfo.InvariantCulture) AndAlso
        DateTime.ParseExact(r("Column2").ToString(), "d.M.yyyy", System.Globalization.CultureInfo.InvariantCulture) >= DateTime.ParseExact(girisTarihi, "d.M.yyyy", System.Globalization.CultureInfo.InvariantCulture)
    ).CopyToDatatable,DT.Clone)

Hope it will helps you :slight_smile:
Cheers!!

1 Like

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