Please help to find out net variance between NetHrs Clocked and Net Hrs due of the employee RRS feed

  • Question

  • I am looking for the help to create the function in C# to find the  Variance Hrs  between  His DueHrs and ClockedHrs

    If an Employee come in 15 minitus  early or leave 15 mins late then only 10 mins be considered as  his extra time worked. So his extra time would be considered only  after 10 mins from clock in and clock out

    But if  he clocked in  5  mins late and he left 12 mins late  then  his variance would be 0. Because after compensating his late coming , he has only balance  7 mins.  that means after compensating the late hrs, he has excess 10 mins, then the variance would be  the differece after 10 mins.

    if an employee is not entitled to work but if he has come for work , then the variance would be   the difference  between the clockout and clockin. [10 mins rule will not be applied]

    Please find my workout in excel given below. Every calculation is done in mins . Please can  you help me how to write  a function in c# to get the variance

    With Thanks



    • Edited by polachan Thursday, December 12, 2019 11:37 PM correction
    Thursday, December 12, 2019 11:24 PM

All replies

  • Is this a homework problem?  What have you done so far?

    Note that the actual times are irrelevant.  It's only the "Net Hrs Due" and the "Net Clock Min" that matter.

    Also, by your rules, your "variance" numbers aren't right.  They should all be a multiple of 10, except for the two not entitled to work.  In the first line, 502 minutes minus 30 break is 472.  472-450 rounded to a multiple of 10 is 20, not 11.  The second line should be 10.  The third line should be 10, then 20.

    If your rules are accurate, here is the code:

        if( NetHrsDue == 0 )
            Variance = NetClockMin;
            Variance = (NetClockMin - BreakMin - NetHrsDue) / 10 * 10;

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Friday, December 13, 2019 12:29 AM
  • I am looking for a function to find the correct variance after including all the scenarios.

    for example if an employee is clockin in 8.59 and clockcout  17.21  break hours .30 Hrs , Enttiled in 9am , Entitled clockout 17.30 , then   the varaince must be 11 mins

    because he clock in 1 mins less than  due time , it should not be considered , and  clockout 17.21 the extra time should be 11 after excluding the 10 mins

    if he come 8.58 and clockout 17.9 there should not be variance

    if clock in 9.04 and clockout 17.12 then the variance 

    Intime - 4 mins short , and clockout +12 then difference +8 so the variance should be 0


    • Edited by polachan Friday, December 13, 2019 7:09 AM
    Friday, December 13, 2019 7:02 AM
  • OK, I think I have the code, but your own chart is not consistent.

    Here's what I think you said. 

    1. If there is no "entitled time", then the variance is the total time worked.  You'll have to decide whether to add the break time after 4 hours.

    2. Otherwise, if they are BOTH "early in" and "late out", then the variance is the sum of the extra minutes beyond 10 minutes at each end.

    3. Otherwise, if they worked MORE than the entitled time, then the variance is the extra minus 10 minutes.

    4. Otherwise, if they worked LESS than the entitled time, then the variance is the shortage.  No 10 minute adjustment.

    With that, I match most of your numbers, although there are some rows I think are wrong.  For example, the 4th row (528,1031,503), that's 12 minutes early and 11 minutes late.  By your rules, the variance should be 3.  You have 12.

    In the 7th row (544,1041,497), that's 4 minutes late and 21 minutes late.  21-4 is 17, so the variance should be 7, not the 1 you show.

    In the 11th row (538,780,242), that's 2 minutes early and 240 minutes early, minus 30 minutes because they didn't work long enough to get lunch.  That should be a variance of -208, not -240.

    And row 14 should be -207, not +207.

    Given all that, this code does what you want.

        int variance = 0;
        if( row.NetHrsDue > 0 )
            // Compute the difference at start time and end time.
            // These numbers are positive if they put in extra time,
            // and negative if they were late getting in or early out.
            int deltain = row.EntIn - row.ActIn;
            int deltaout = row.ActOut - row.EntOut;
            // If they worked less than 6 hours, then they didn't take
            // a lunch break.
            if( row.NetClockMins < 360 )
                deltaout += row.BreakMins;
            // If they had extra time on both ends, they lose the first
            // 10 minutes of the extra.
            if( deltain > 0 && deltaout > 0 )
                variance = Math.Max( 0, deltain-10 ) + Math.Max( 0, deltaout-10 );
            // If they had a net overtime, they lose the first 10 minutes of it.
            else if( deltain + deltaout > 0 )
                variance = Math.Max( 0, deltain + deltaout - 10 );
            // Otherwise, they were net short.
                variance = deltain + deltaout;
            variance = row.NetClockMin;
            if( row.NetClockMin >= 360 )
                variance -= row.BreakMins;
        Console.WriteLine( row.NetClockMin, variance, row.Variance );

    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    Saturday, December 14, 2019 12:22 AM