Get Min / Max Date from DataTable

I have a column of data which is in format dd/MM/yyyy but type is String. I want to fetch the max and min value in format dd/MM/yyyy.
As in column it is in text format, i tried Cdate(row(“date”).toString) and also DateTime.ParseExact but getting error :- Conversion from String “27/03/2021” to Date is not valid

1 Like

we can do:
DateTime.ParseExact(“27/03/2021”, “dd/MM/yyyy”, CultureInfo.InvariantCulture)
[03/27/2021 00:00:00]

Edited: fixed minor bug in format string

Hi

Try with this expression for DateTime version

DateTime.ParseExact(row(“date”).ToString.Trim.SubString(0,10), “dd/MM/yyyy”, system.Globalization.CultureInfo.InvariantCulture)

This will ensure that only first ten letters are considered because sometimes when reading from excel it might give in this format

dd/MM/yyyy hh:mm:ss

So here we are taking only this

dd/MM/yyyy. By using substring(0,10)

Cheers @Shilpa_Mohanty

Hi,

Please try the following steps. 3 images are combined in 1

Variables:

grafik

LINQ:

(From d In dtData.AsEnumerable
Where DateTime.TryParseExact(d("Column1").toString.trim, "dd/MM/yyyy", CultureInfo.InvariantCulture,DateTimeStyles.None, Nothing)
Select dp = DateTime.ParseExact(d("Column1").toString.trim, "dd/MM/yyyy", CultureInfo.InvariantCulture)
Order By dp).toarray

Min = arrDates.FirstOrDefault()
Max = arrDates.LastOrDefault()

grafik

Ensure following:
grafik

in case of the data column value cannot be parsed it will be filtered out. We can adopt as needed

  • the substringing as mentioned by Palani
  • handling multiple format patterns

Find starter help here:
FromDT_GetDate_MinMax.xaml (7.7 KB)


Tried this but its giving output with time and the format here in output is MM/dd/yyyy instead of dd/MM/yyyy

1 Like

No worries

I got to see a custom component in this

Have a look on this

Cheers @Shilpa_Mohanty

1 Like

We cant use BalaReva activities

Hmm
Fine

You can use direct expression like this