fishbowlstudios
asked on
Calculate Time worked in Gridview
I am working on a program to calculate hours worked for an employee. How do I take two time values from two gridview columns and add them together? Should I use a template field?
ASKER
DateTime Values come from a Database via a LINQ query. I assume they are coming from a DateTime datatype.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
TimeSpan it is:
Employee item = e.Row.DataItem as Employee;
TimeSpan hoursWork = item.endDate.Subtract(item .startDate );
Console.WriteLine(hoursWor k.TotalHou rs.ToStrin g());
//Assign hoursWork to your template field.
Or, if you rather have two timespans:
Employee item = e.Row.DataItem as Employee;
TimeSpan workHours = item.workPeriod1.Add(item. workPeriod 2);
Console.WriteLine(workHour s.TotalHou rs.ToStrin g());
//Assign workHours to your template field.
/gustav
Employee item = e.Row.DataItem as Employee;
TimeSpan hoursWork = item.endDate.Subtract(item
Console.WriteLine(hoursWor
//Assign hoursWork to your template field.
Or, if you rather have two timespans:
Employee item = e.Row.DataItem as Employee;
TimeSpan workHours = item.workPeriod1.Add(item.
Console.WriteLine(workHour
//Assign workHours to your template field.
/gustav
Is the data in both columns expressed as hours or Date/Time values like a Start and End time?
Keith