hi, im creating a payroll system for my project and part of it is a time calculator and my problem is I really don't know how to deduct late. it should work this way "for every minute of late, their daily rate will be deducted 1.16"
what i did is i created a textbox that will contain their monthly rate and it is save in a database and I created another textbox that will contain the number of days in a month then ill just devide the of days in a month to their monthly rate to get their daily rate. for the time calculator i have created 8 textboxes. textbox1 is for AM IN, textbox2 is for OUT, textbox3 is for PM IN, textbox4 is for PM OUT, textbox5 is for the total working hours in the morning, textbox6 is for the total working hours in the afternoon, textbox7 is for the total working hours in a day and textbox8 for their salary at that day.

this is the code i used, i only got it from this site and it realy helps me to calculate the time.
    Dim d1 As DateTime
    Dim d2 As DateTime
    Dim ts11 As TimeSpan
    Dim ts22 As TimeSpan
    Dim tsfinal1 As TimeSpan



    TextBox9.Text = Val(SalTextBox.Text) / Val(TextBox8.Text)

    d1 = DateTime.Parse("1/1/2012 " + Me.TextBox1.Text.Trim)
    d2 = DateTime.Parse("1/1/2012 " + Me.TextBox2.Text.Trim)
    ts11 = d2 - d1

    TextBox5.Text = (ts11.ToString)


    d1 = DateTime.Parse("1/1/2012 " + Me.TextBox3.Text.Trim)
    d2 = DateTime.Parse("1/1/2012 " + Me.TextBox4.Text.Trim)
    ts22 = d2 - d1

    TextBox7.Text = (ts22.ToString)

    tsFinal1 = ts11 + ts22
    TextBox7.Text = tsfinal1.ToString`

please help me on how will i calculate their late and how will i deduct it to their daily rate.
every help will be very much appreciated.

Your approach is correct, but I think you're calculating the worked hours and salary before calculating the employee's late minutes.

A simpler approach is:

  1. Define the official start time (for example, 8:00 AM).
  2. Compare the employee's actual check-in time with the scheduled start time.
  3. If the employee arrives after 8:00 AM, calculate the number of late minutes.
  4. Multiply the late minutes by the deduction per minute.
  5. Subtract the result from the employee's daily salary.

For example:

Dim scheduledTime As DateTime = DateTime.Parse("1/1/2012 8:00 AM")
Dim actualTime As DateTime = DateTime.Parse("1/1/2012 " & TextBox1.Text)

If actualTime > scheduledTime Then
    Dim lateMinutes As Integer = CInt((actualTime - scheduledTime).TotalMinutes)

    Dim deductionPerMinute As Decimal = 1.16D
    Dim lateDeduction As Decimal = lateMinutes * deductionPerMinute

    Dim dailyRate As Decimal = CDec(SalTextBox.Text) / CDec(TextBox8.Text)

    Dim dailySalary As Decimal = dailyRate - lateDeduction

    TextBox10.Text = lateMinutes.ToString()
    TextBox11.Text = lateDeduction.ToString("0.00")
    TextBox12.Text = dailySalary.ToString("0.00")
Else
    TextBox10.Text = "0"
    TextBox11.Text = "0.00"
    TextBox12.Text = dailyRate.ToString("0.00")
End If

This keeps the calculation easy to understand:

Calculate the employee's daily rate.
Calculate late minutes.
Multiply by the deduction rate (1.16 per minute).
Subtract the deduction from the daily rate.

If your payroll system also needs to calculate overtime, undertime, or half-day attendance, it's a good idea to keep each calculation in a separate function. That makes the code much easier to maintain and debug later.

The same principle is used in many attendance and payroll tools. For example, a college attendance calculator compares attended classes against the total classes to calculate attendance percentage, while a payroll system compares actual check-in time against the scheduled start time to calculate late deductions. In both cases, the key is comparing the actual value with the expected value before applying the final calculation.

commented: I was looking for the same answer for about two days +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.