Time

Hi,
I am reading time from an excel table which is in hh:mm format. I need to sum all these columns to get total minutes.

How to do this? When I read the cell from Excel, it comes as string.

Thank you,

@A_Learner,

I’m considering you are reading the excel file to a Datatable. Use below LINQ in assign activity.

totalMinutes = dataTable.AsEnumerable().Sum(Function(row) Convert.ToInt32(row("TimeColumnName").ToString().Split(":"c)(0)) * 60 + Convert.ToInt32(row("TimeColumnName").ToString().Split(":"c)(1)))

This should give you total minutes.

Thanks,
Ashok :slight_smile:

1 Like

@A_Learner

Better to use timespan parse to parse this …please check the same…One verification you need to do is the format in which it is being read from excel…that you would know from locals panel after reading the data and checking the corresponding data table

RequiredSum = dt.AsEnumerable.Sum(function(x) TimeSpan.Parse(x("ColumnName").ToString).TotalMinutes)

image

Sample implementation
image

Hope this helps

cheers

1 Like

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