Get latest and earliest date from column

Hello

I have a datatable with a column that contain dates in the format dd-MM-yyyy.
I would like to fetch the earliest and latest date from this column.

Example:

Dates
01-04-2024
04-04-2024
01-05-2024
17-05-2024
05-05-2024

Earliest should be: 01-04-2024
Latest should be: 17-05-2024

Regards
Soren

Hi @SorenB

earliestDate = dt.AsEnumerable() _
    .Select(Function(row) DateTime.ParseExact(row("Dates").ToString(), "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture)) _
    .Min().ToString("dd-MM-yyyy")
latestDate = dt.AsEnumerable() _
    .Select(Function(row) DateTime.ParseExact(row("Dates").ToString(), "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture)) _
    .Max().ToString("dd-MM-yyyy")

Regards,

1 Like

Thank you @lrtetala

Regards
Soren

1 Like

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