I already search this question but unfortunately couldn't find proper answer.
I want to calculate the average of time spent on doing something in 10 different day and I have 10 datetimepicker
for start time and also 10 datetimepicker
for end time for each day (in total 20 datetimepicker
).
now I want to get the average of time spent for work in these 10 days.
this is what I've done for calculating timespan
in each day and now I don't know how to calculate average if these timespans
of course I want to know is there any shorter way to get the job done?
DateTime Dt1 = dateTimePicker1.Value;
DateTime Dt2 = dateTimePicker2.Value;
.
.
.
DateTime Dt20 = dateTimePicker20.Value;
TimeSpan Day1 = DateTime.Parse(Dt11.TimeOfDay.ToString()).Subtract(DateTime.Parse(Dt1.TimeOfDay.ToString()));
TimeSpan Day2 = DateTime.Parse(Dt12.TimeOfDay.ToString()).Subtract(DateTime.Parse(Dt2.TimeOfDay.ToString()));
.
.
.
TimeSpan Day10 = DateTime.Parse(Dt20.TimeOfDay.ToString()).Subtract(DateTime.Parse(Dt10.TimeOfDay.ToString()));
I want to find average of Day1 to Day10
TimeSpan
values and then reparsing them, either.) – Protoactiniumdatetimepicker
and I parse it back just because I saw someone did that in one of topics, – Kuehlvar MyTimeSpan = myDateTime1 - myDateTime2;
seems to do the trick withoutTimeOfDay
orToString()
(that last one is really amazingly useless but incredibly common for some reason). – Debose