Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am trying to calculate the amount of time on a daily basis.

Currently I have calculated "[total hours per diem]", "[total days]" and the time values (if not split over multiple days).

Where I am having trouble is in calculating the total time spent if the event is not an "all day event" and falls over multiple days.

For example:

If I had 1/1/2013 12:00 PM (Start Date) and 1/2/2013 4:00 PM (End date). I would like to have the result be 8 hours ((4 hours per day day) * (2 days)). What I actually end up with is 28 hours (the difference between the two times).

It should be something like =([total days]*(*time difference of end time - start time)) but I can't figure out how to just pull the time for a single day.

Thank you in advance

share|improve this question

1 Answer 1

var startDate = Convert.ToDateTime("1/1/2013 12:00 PM");
var endDate = Convert.ToDateTime("1/2/2013 4:00 PM");

var diffHours = (endDate.Hour - startDate.Hour);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.