I use timespan and datetime pickers in my project, it calculates correctly for todays time for eg.,(dtpouttime-dtpintime), but in case if there is shift which starts today
and ends the next day and probably that may even extend to one more day(If the employee works over time ).I am finding difficulty in calculating this, cam any one help me ,how to calclate this thing.
Thanks in Advance,
A.Durga Prasad
Loading
AlanPosted Aug 9, 2008, 2:51 PM
I imagine that this is a continuation of your previous threads about calculating TimeSpans.
If people may work overnight, then an easy way to adjust for this without interfering too much with the existing code is this:
TimeSpan ts = dtpouttime.Value.TimeOfDay - dtpintime.Value.TimeOfDay;
if (ts.TotalHours < 0)
{
ts = ts.Add(TimeSpan.FromHours(24));
}
ts = ts.Subtract(TimeSpan.FromMinutes(30)); // subtract 30 mins for lunch
// rest of code same as before
Surely it's not possible for a shift to last more than 24 hours unless, perhaps, the workers are programmers ;)
If it is, how many 30 mins 'lunch' breaks would be allowed? What about a 'sleep' break?