Extract date value from Data-Table in String format

Hello all, I wish to extract the date value from the data table column name ‘to’ in string format. Can someone help me out or share a workflow to do the same.

Thanking you.

Regards,
Hardik Durgam

Hi @Hardik_Durgam,

Are you able to extract datatable? If yes try this.

Dt(0)(“to”).Tostring

If no you can use Get text activity to extract that value.

1 Like

@Harshith_Adyanthaya thanks for your solution. In the same data-table under the column name “to” if I have multiple dates like 28.03.2024 , 30.03.2024, etc and out of these dates I have to extract the date which is latest. Can you help me out in this?

Regards,
Hardik Durgam

Hi @Hardik_Durgam,

Try this.

Dt.AsEnumerable().Max(Function (drRows) DateTime.Parse(drRows.Item(“to”).ToString)).ToString

OR

maxDate = Convert.ToDateTime(dataTable.Compute(“MAX(to)”, null))

Hi,

Do you mean “28.03.2024 , 30.03.2024” exists in single cell?

If so, the following helps you.

CurrentRow("to").ToString.Split({","c}).Max(Function(s) DateTime.ParseExact(s.Trim,"dd.MM.yyyy",System.Globalization.CultureInfo.InvariantCulture)).ToString("dd.MM.yyyy")

Or if you need to extractthe latest date in the “to” column, the following will work.

dt.AsEnumerable.Max(Function(r) DateTime.ParseExact(r("to").ToString.Trim,"dd.MM.yyyy",System.Globalization.CultureInfo.InvariantCulture)).ToString("dd.MM.yyyy")

Regards,

@Harshith_Adyanthaya I tried your first approach but it is giving me an error saying “String was not recognized as valid DateTime”.

Regards,
Hardik Durgam

@Yoichi dates are stacked over one another in a single column, and the column header is “to”

Regards,
Hardik Durgam

Dt.AsEnumerable().Max(Function (drRows) DateTime.ParseExact(drRows(“to”).ToString,“dd.MM.yyyy”,System.Globalization.CultureInfo.InvariantCulture)).ToString(“dd/MM/yyyy”)

This should work.

Hi,

The following expression will work. Can you try this?

@Harshith_Adyanthaya this entire expression is in a single line right? . What should be the data type of the variable storing the output?

Yes. Its String.

Thanks for your solution :grinning:

Regards,
Hardik Durgam

1 Like

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